/WebQuery

Anki Addon with addtional widget displaying related information on the web and capture as image

Primary LanguagePython

Web Query

Version

Compatable for Anki 2.1.x ONLY

Main features

  • Search web using provided URL and display during card review. Search the 1st Field of current note
  • Capture web image as card resource and save into note

中文说明点这里

Installation

Use the installation code: 627484806

Instructions

Capture Image into Note Field

  1. Click on button 'Capture' at the button
  2. Crop the region of image
  3. Select your note field and save
  4. Cropped images will be saved to your resource folder of the profile

Capture Text into Note Field

Select text in the web and right click to show context menu and save.

User Configurations

In the "Options" menu open the configuration dialog:

{
    "image_quality": 50,
    "load_on_question": false,
    "preload": true,
    "provider_urls": [
        [
            "Bing",
            "https://www.bing.com/images/search?q=%s"
        ],
        [
            "Wiki",
            "https://en.wikipedia.org/wiki/?search=%s"
        ],
        [
            "WordRoot",
            "http://www.youdict.com/root/search?wd=%s~~#article"
        ]
    ]
}
  • image_quality: Saved image quality, up to 100, default 50.
  • load_on_question": change to false if you need web to be queried /ONLY/ on answers.
  • preload: Query web even it's invisible.

Load on Card Interval

Config item "load_when_ivl", defaults to ">=0", this value controls the visibility of Web Query dock widget based on current card's intervals:

  • New Card: "==0"
  • Review Card: ">0"
  • Mixed: ">=0"
  • Interval within 3 days: "<=3"

When you're looking at the source:

eval(str(self.card.ivl) + UserConfig.load_when_ivl)

You can see that this actually is implemented by Python "eval" .. so you can even set the value as, 1<= interval <=10 and :

{
"load_when_ivl": " in range(1,10)"
}

Provider URL

This is an URL string you can customize in your settings. By default, This addon provide a value for Wikipedia: http://en.wikipedia.org/wiki/wiki.html?search=%s

Please note the "%s" at the end for "search=%s" which mean the parameter where addon will fill during the review.

Extract Web Elements (CSS Selectors)

Although this addon is powerful enough, but sometimes we need to reference parts the web's information and others are not wanted, in this case you can use Standard CSS2 selector syntax to query partially.

Append selectors at the last of your provider url, separate by "~~":

[
    "WordRoot",
    "http://www.youdict.com/root/search?wd=%s~~#article"
]

Above provider url only return the tag(ID = article) HTML in Web Query.

Get Provider URL

You would be able to search the web for more provider URL patterns, or make your own just from your browser address bar:

  1. Search images in www.bing.com for keyword "anki"
  2. I got the URL like this from browser: https://cn.bing.com/images/search?q=anki&FORM=HDRSC2
  3. Replace "anki" with "%s" in the parameters "search?q=anki"
  4. The Provider URL is https://cn.bing.com/images/search?q=%s&FORM=HDRSC2

Update Provider URL

Every Provider URL should have and only one '%s' place holder.

  1. Go to "Tool" > "Addons" and find "WebQuery"
  2. Click on "Settings"
  3. Find item "provider_urls", you can fill as much as you want, those multiple items will be shown in tabs:
"provider_urls": [
    [
      "Bing",
      "https://www.bing.com/images/search?q=%s"
    ],
    [
      "Wiki",
      "https://en.wikipedia.org/wiki/?search=%s"
    ]
  ],

Toggle Tab Visibility

Just in case you have plenty of url providers and there must to be many tabs on the widget, you can set visibilities of those tabs to each NOTE TYPE, by default they are all turned on for all.

  1. Go to menu "Tool" > "Manage Note Types" > Select one note
  2. Click on button "Web Query Tab Visibility"
  3. Check the visibilities for each of the provider url:

More Provider URL

Speical thanks to @语言-Rahanande for collection