diff --git a/src/ajax.js b/src/ajax.js index 63ba3ba..13a6fef 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -17,7 +17,7 @@ async function ajax_execute(ajax, keyword) { console.debug("ajax_execute()"); const before_start = 100; - var slow = 10; + var slow = 20; async function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -90,11 +90,27 @@ async function ajax_execute(ajax, keyword) var web_inputbox; + await sleep(slow * 5); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.click(); + await sleep(slow * 5); web_inputbox = document.querySelectorAll(queryStr)[0]; web_inputbox.focus(); + await sleep(slow * 5); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.dispatchEvent ( new KeyboardEvent( "keypress", { key: " ", keyCode: 32, bubbles: true } ) ); + + await sleep(slow * 5); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.dispatchEvent ( new KeyboardEvent( "keydown", { key: " ", keyCode: 32, bubbles: true } ) ); + + await sleep(slow * 1); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.dispatchEvent ( new KeyboardEvent( "keyup", { key: " ", keyCode: 32, bubbles: true } ) ); + await sleep(slow * 2); web_inputbox = document.querySelectorAll(queryStr)[0]; web_inputbox.dispatchEvent ( new Event( "input", { bubbles:true } ) ); @@ -103,10 +119,27 @@ async function ajax_execute(ajax, keyword) web_inputbox = document.querySelectorAll(queryStr)[0]; web_inputbox.dispatchEvent ( new Event( "change", { bubbles:true } ) ); + + + await sleep(slow * 5); web_inputbox = document.querySelectorAll(queryStr)[0]; web_inputbox.value = keyword ; + + + await sleep(slow * 5); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.dispatchEvent ( new KeyboardEvent( "keypress", { key: " ", keyCode: 32, bubbles: true } ) ); + + await sleep(slow * 5); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.dispatchEvent ( new KeyboardEvent( "keydown", { key: " ", keyCode: 32, bubbles: true } ) ); + + await sleep(slow * 1); + web_inputbox = document.querySelectorAll(queryStr)[0]; + web_inputbox.dispatchEvent ( new KeyboardEvent( "keyup", { key: " ", keyCode: 32, bubbles: true } ) ); + await sleep(slow * 2); web_inputbox = document.querySelectorAll(queryStr)[0]; web_inputbox.dispatchEvent ( new Event( "input", { bubbles:true } ) ); @@ -115,6 +148,8 @@ async function ajax_execute(ajax, keyword) web_inputbox = document.querySelectorAll(queryStr)[0]; web_inputbox.dispatchEvent ( new Event( "change", { bubbles:true } ) ); + + if (pressEnter) { await sleep(slow * 5); diff --git a/src/background.js b/src/background.js index e49c510..0b4bf15 100644 --- a/src/background.js +++ b/src/background.js @@ -167,7 +167,13 @@ async function set_contextmenu() { break; case "popup": default: - onMenuClickFunc_open = function() { chrome.browserAction.openPopup() ; } ; + onMenuClickFunc_open = function() { + // NOTE !!!! NOTICE !! ` openPopup ` not allow above have ` await ` + if (mv>=3) + chrome.action.openPopup() ; + else + chrome.browserAction.openPopup() ; + } ; break; } @@ -203,6 +209,7 @@ async function setContextMenuOrKeyShortcutCopyBehavior() var setting_copyOnContextMenuOrKey = await get_addon_setting_local('copyOnContextMenuOrKey') ; if (setting_copyOnContextMenuOrKey) onMenuClickOrKeyFunc_copy = function(str) { + // NOTE !!!! NOTICE !! ` permissions.request ` not allow above have ` await ` chrome.permissions.request( { permissions: ['clipboardWrite'] } , r=>console.log(r) ); navigator.clipboard.writeText(str) ; } ; @@ -214,7 +221,13 @@ async function setContextMenuOrKeyShortcutCopyBehavior() chrome.commands.onCommand.addListener(async function (command, tab) { // 'tab' is only in mv3 if (command == "selection_as_search_then_open_popup") - try { chrome.browserAction.openPopup() ; } catch(err) { console.warn(err) } + try { + // NOTE !!!! NOTICE !! ` openPopup ` not allow above have ` await ` + if (mv>=3) + chrome.action.openPopup() ; + else + chrome.browserAction.openPopup() ; + } catch(err) { console.warn(err) } else if (command == "selection_as_search_then_open_sidebar") try { chrome.sidebarAction.open() ; } catch(err) { console.warn(err) } @@ -222,10 +235,12 @@ chrome.commands.onCommand.addListener(async function (command, tab) { // 'tab' i // console.debug("onCommand selection_as_search"); + // NOTE !!!! NOTICE !! ` permissions.request ` not allow above have ` await ` await chrome.permissions.request({ permissions: ["activeTab"] }); if (mv >= 3) { + // NOTE !!!! NOTICE !! ` permissions.request ` not allow above have ` await ` await chrome.permissions.request({ permissions: ["scripting"] }); chrome.scripting.executeScript( { diff --git a/src/engine_handle.js b/src/engine_handle.js index fa9e73d..29f9df5 100755 --- a/src/engine_handle.js +++ b/src/engine_handle.js @@ -359,54 +359,55 @@ function getDataForGo(engine,btn,dbname=null) } -var newTabBringFront; -async function goEngBtn(engine,btn,keyword,dbname=null) -{ - var newTabIndex = -1 ; - if (window.run_env != "http_web") { - var setting_newTabPos = await get_addon_setting_local('newTabPos'); - switch (setting_newTabPos){ - case 'left-all': newTabIndex = 0 ; break; - case 'right-all': newTabIndex = 99999999 ; break; - case 'left-current': - case 'right-current': - await chrome.tabs.query( - { currentWindow: true , active: true}, - async function(r) { - console.log(r); - newTabIndex = r[0].index ; - if (setting_newTabPos == 'right-current') - newTabIndex = r[0].index+1; - } - ) ; - break; - - default: newTabIndex = 0; - } - - newTabBringFront = false; - - //----------------------------- - async function zzsleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); - } - for ( var zz=0; zz<1000; zz++) { - if (newTabIndex != -1) - break; - else if (zz==999) - { - console.error('Waiting for newTabIndex, but timeout !') - return; +async function calcNewTabIndex() { + var newTabIndex = -1; + var setting_newTabPos = await get_addon_setting_local('newTabPos'); + switch (setting_newTabPos){ + case 'left-all': newTabIndex = 0 ; break; + case 'right-all': newTabIndex = 99999999 ; break; + case 'left-current': + case 'right-current': + await chrome.tabs.query( + { currentWindow: true , active: true}, + async function(r) { + console.log(r); + newTabIndex = r[0].index ; + if (setting_newTabPos == 'right-current') + newTabIndex = r[0].index+1; } - await zzsleep(5); - } - //------------------------------ + ) ; + break; + + default: newTabIndex = 0; } + + //----------------------------- + async function zzsleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + for ( var zz=0; zz<1000; zz++) { + if (newTabIndex != -1) + break; + else if (zz==999) + { + console.error('Waiting for newTabIndex, but timeout !'); + break; + } + await zzsleep(5); + } + //------------------------------ + return newTabIndex; +} +var newTabBringFront = false; +var newTabIndex = -1 ; +async function goEngBtn(engine,btn,keyword,dbname=null) +{ + if ( dbname == "browser" ) { - + newTabIndex = await calcNewTabIndex(); if (isFirefox) { const newTab = ( await browser.tabs.create({url:"about:blank", active: newTabBringFront, index: newTabIndex}) ); @@ -481,6 +482,7 @@ async function goEngBtn(engine,btn,keyword,dbname=null) go_full_url(keyword, data.full_url, data.charset,use_referer); else { + newTabIndex = await calcNewTabIndex(); await open_connecting_page(dbname, engine, btn, keyword, newTabIndex); } return; @@ -495,6 +497,16 @@ async function goEngBtn(engine,btn,keyword,dbname=null) if (window.run_env == "http_web") { } + + if (mv >= 3) { + // NOTE !!!! NOTICE !! ` permissions.request ` not allow above have ` await ` + var r = await chrome.permissions.request({ permissions: ["scripting"] }); + if ( !r ) { + console.error("Failed to get 'scripting' permission"); + return; + } + } + var permis_have; if (isFirefox) { permis_have = await browser.permissions.getAll(); @@ -504,18 +516,6 @@ async function goEngBtn(engine,btn,keyword,dbname=null) }) ); } - if (mv >= 3) - { - if ( ! permis_have['permissions'].includes('scripting') ) - { - var r = await chrome.permissions.request({ permissions: ["scripting"] }); - if ( !r ) { - console.error("Failed to get 'scripting' permission"); - return; - } - - } - } var host_permis_needed = removeUrlParts(data.action) + '*'; @@ -529,7 +529,9 @@ async function goEngBtn(engine,btn,keyword,dbname=null) return; } - + + + newTabIndex = await calcNewTabIndex(); var newTab; if (isFirefox) { @@ -586,7 +588,8 @@ async function goEngBtn(engine,btn,keyword,dbname=null) if (window.run_env == "http_web") form_submit(fparams, data.action, data.charset, data.method, use_referer); else{ - await open_connecting_page(dbname, engine, btn, keyword, newTabIndex); + newTabIndex = await calcNewTabIndex(); + await open_connecting_page(dbname, engine, btn, keyword, newTabIndex); } } diff --git a/src/enginesdata.js b/src/enginesdata.js index 1b2de9f..a8c443d 100644 --- a/src/enginesdata.js +++ b/src/enginesdata.js @@ -94,6 +94,7 @@ catas = { label: '💻' + i18n(["软件程序", "Programing"]), engines: [ { type:"engine", name:"github"}, + { type:"engine", name:"python"}, { type:"engine", name:"mdn"}, { type:"engine", name:"chrome_ext_dev"}, { type:"engine", name:"stackexchange"}, @@ -183,7 +184,7 @@ catas = { ], }, "translate": { - label: '🔠' + i18n(["多国译典", "Translates"]), + label: '🔠' + i18n(["多国译查", "Translates"]), engines: [ { type:"engine", name:"youdao" , visible_lang: "zh"}, { type:"engine", name:"baidu_translate" , visible_lang: "zh"}, @@ -195,7 +196,7 @@ catas = { ], }, "academy": { - label: '📑' + i18n(["资科藏识", "Knowledge"]), + label: '📑' + i18n(["资科知识", "Knowledge"]), engines: [ // { type:"label", lstr:i18n(["资料专藏", "Knowledge Search Engines"])}, { type:"engine", name:"wikip_zh", visible_lang: "zh"}, @@ -218,21 +219,24 @@ catas = { ], }, "han": { - label: "🀄漢語華文", + label: "🀄漢言文藏", visible_lang: "zh", engines: [ - { type:"label", lstr:"辭言字海" }, + { type:"label", lstr:"字言辭海" }, { type:"engine", name:"zdic"}, { type:"engine", name:"ccamc"}, { type:"engine", name:"moedict"}, - { type:"engine", name:"works.hk"}, - { type:"engine", name:"cantodict"}, - { type:"engine", name:"voicedic"}, { type:"engine", name:"shenyandayi"}, { type:"engine", name:"zitools"}, { type:"label", lstr:"帛竹卷經" }, { type:"engine", name:"ctext"}, { type:"engine", name:"kanripo"}, + { type:"label", lstr:"南腔北调" }, + { type:"engine", name:"shyyp"}, + { type:"engine", name:"jyut_net"}, + { type:"engine", name:"works.hk"}, + { type:"engine", name:"cantodict"}, + { type:"engine", name:"voicedic"}, { type:"label", lstr:"汉符编码" }, { type:"engine", name:"unicode"}, { type:"engine", name:"zi-hi"}, @@ -1247,7 +1251,7 @@ sEngines = { btns: { "baidu": { "label": "百度", - "kw_format": "site:(www.coolapk.com) {0}", + "kw_format": "{0} site:(www.coolapk.com)", "use_other_engine": { "engine": "baidu", "btn": "sch" @@ -1255,7 +1259,7 @@ sEngines = { }, "google": { label: "Google", - kw_format: "{0} site:www.coolapk.com", + kw_format: "{0} site:www.coolapk.com", use_other_engine: { engine: "google", btn: "search" @@ -1461,7 +1465,7 @@ sEngines = { "baidu": { "label": "百度", visible_lang: "zh", - "kw_format": "site:(apps.apple.com) {0}", + "kw_format": "{0} site:(apps.apple.com)", "use_other_engine": { "engine": "baidu", "btn": "sch" @@ -1469,7 +1473,7 @@ sEngines = { }, "google": { label: "Google", - kw_format: "{0} site:apple.com/*app", + kw_format: "{0} site:apple.com/*app", use_other_engine: { engine: "google", btn: "search" @@ -1516,6 +1520,22 @@ sEngines = { }, } }, + "python": { + dname: "Python", + addr: "https://docs.python.org", + btns: { + "doc": { + label: "Search Doc", + action: "https://docs.python.org/3/search.html", + kw_key: "q", + }, + "pypi": { + label: "PyPI", + action: "https://pypi.org/search/", + kw_key: "q", + }, + } + }, "mdn": { "dname": "MDN", "addr": "https://developer.mozilla.org", @@ -1527,7 +1547,7 @@ sEngines = { }, "sch_google": { "label": " Google", - "kw_format": "{0} site:developer.mozilla.org/en-US", + "kw_format": "{0} site:developer.mozilla.org/en-US", "use_other_engine": { "engine": "google", "btn": "search", @@ -1560,12 +1580,12 @@ sEngines = { "search": { label: "Search", "action": "https://developer.chrome.com/docs/extensions/reference/", - "ajax": ".search-box__input" + "ajax": ".devsite-search-field" }, "google": { label: "Google", - kw_format: "{0} site:developer.chrome.com/docs/extensions/*", + kw_format: "{0} site:developer.chrome.com/docs/extensions/*", use_other_engine: "google" } } @@ -1647,7 +1667,7 @@ sEngines = { "search": { label: "Search", action: "https://formulae.brew.sh/", - ajax: "#search-bar" + ajax: [700, "#search-container button", 700, "#docsearch-input", 10] } } }, @@ -1765,6 +1785,38 @@ sEngines = { } } }, + "shyyp": { + dname: "羊羊粤语", + addr: "https://shyyp.net", + btns: { + 'search': { + label: "搜索", + action: "https://shyyp.net/", + ajax: ["#mainSearchInput", 10 ], + }, + "enter": { + label: "进入", + full_url: "https://shyyp.net/w/{0}", + } + }, + }, + "jyut_net": { + dname: "粵音資料集叢", + addr: "https://jyut.net/", + d_addi_html: "繁", + kw_key: "q", + btns: { + "char": { + label: "查單字", + action: "https://jyut.net/query", + }, + "ping": { + label: "粵拼查", + action: "https://jyut.net/search", + }, + + }, + }, "cantodict": { "dname": "CantoDict", "tip": "CantoDict is a unique collaborative English/Cantonese/Mandarin dictionary", @@ -1817,26 +1869,36 @@ sEngines = { action: "https://zh.voicedic.com/", btns: { "Cantonese": { - "label": "广州话", - "ajax": ["input[name=language][value=Cantonese]",100,".s_ipt",100,".s_btn"] + "label": "广东话", + "ajax": [ + "input[name=language][value=Cantonese]", + 100,".s_ipt",100,".s_btn"] }, + "Waitau": { + "label": "围头话", + "ajax": [ + "input[name=language][value=Waitau]", + 100,".s_ipt",100,".s_btn"] + }, "Shanghaiese": { - "label": "上海话", - "ajax": ["input[name=language][value=Shanghaiese]",100,".s_ipt",100,".s_btn"] + "label": "吴语系", + "ajax": [ + "input[name=language][value=Shanghaiese]", + "input[name=language][value=Suzhouese]", + "input[name=language][value=Vusihlau]", + "input[name=language][value=Wenzhouese]", + 100,".s_ipt",100,".s_btn"] }, - "Chaozhouese": { - "label": "潮州话", - "ajax": ["input[name=language][value=Chaozhouese]",100,".s_ipt",100,".s_btn"] - }, - "minnan": { - "label": "闽南话", + "Minnan": { + "label": "闽南语系", "ajax": [ "input[name=language][value=Minnanese]", "input[name=language][value=Twblg]", + "input[name=language][value=Chaozhouese]", 100,".s_ipt",100,".s_btn"] }, - "hakka": { - "label": "客家话", + "Hakka": { + "label": "客家语系", "ajax": [ "input[name=language][value=Hakka]", "input[name=language][value=Hakkafc]", @@ -1845,9 +1907,13 @@ sEngines = { "input[name=language][value=Hakkatb]", "input[name=language][value=Hakkazhon]", 100,".s_ipt",100,".s_btn"] - }, - - + }, + "Mandarin": { + "label": "南京话", + "ajax": [ + "input[name=language][value=Langjin]", + 100,".s_ipt",100,".s_btn"] + }, } }, "shenyandayi": { @@ -2046,7 +2112,7 @@ sEngines = { "baidu": { "label": "百度", "visible_lang": "zh", - "kw_format": "site:(apps.apple.com) {0} extension", + "kw_format": "{0} extension site:(apps.apple.com)", "use_other_engine": { "engine": "baidu", "btn": "sch" @@ -2054,7 +2120,7 @@ sEngines = { }, "google": { "label": "Google", - "kw_format": "{0} extension site:apple.com/*app", + "kw_format": "{0} extension site:apple.com/*app", "use_other_engine": { "engine": "google", "btn": "search" diff --git a/src/home.html b/src/home.html index dc81cce..2bd81aa 100755 --- a/src/home.html +++ b/src/home.html @@ -149,7 +149,7 @@
Shift+Enter