From c3562524613c50ffbf0e3d3e819a04211b4404fe Mon Sep 17 00:00:00 2001 From: Kaiyuan Liu Date: Mon, 18 Jul 2022 18:24:50 -0400 Subject: [PATCH] 5.2.0 --- CHANGELOG.md | 1 + icons/atom.png | Bin 0 -> 4343 bytes meta/popsearch.meta.js | 2 +- popsearch.user.js | 94 ++++++++++++++++++++++------------------- 4 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 icons/atom.png diff --git a/CHANGELOG.md b/CHANGELOG.md index c8fcc8b..1d5da38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to all the scripts will be documented in this file. ## Popup Search +* 5.2.0: Support function in user engines * 5.1.4: Press Esc to hide popup * 5.1.3: Fix Discuz form replying * 4.4.2: Optimized hiding logic diff --git a/icons/atom.png b/icons/atom.png new file mode 100644 index 0000000000000000000000000000000000000000..2dac769009f24a8ecc91afc6caaf3ac55a34a437 GIT binary patch literal 4343 zcmeH~_dgYm_s8$$;@afedtW!(HOs!&%D78bxK|nJa?42e9$gjEjY#5VRz_5|xZUI; zWsiu2OEQW`sjv6n@%@~~<8@w-^Lm_L&hxi(9p!Ax%O$}D004OH?GTt_Px?<_*5kgr zkoW7@Si`OCabPfbcF|?wc;vin=MjFK`u-=NxVHWDaVQ>vbdSK20wSUaVg7)qs3^^g zp_jtX6E6E}lEMOuH&06d04#?nM;!9szkkR3|EvEI`2R-0^Oe;8@y$mO7-uX1$ifO@ zW9I;Ka&hzU^6?7@o)Cfvi-?MeOGrvd%gD;fD<~={tEfWNU?zucbFP`9c{(^r%V9>?jOT>^+ z(&Z~*;SrHnqpn5A#Ky%ZBqk-Nq^6~3WM*9_XWzJ)lbd%t{|@DDLE*ik;`=2JN*|V$ zQy*1SR#n&3K7R7FuD+r1SyS`#7cW~{+uA!iySiWX^wM6_-}JrhXABGuy&Hc2VPte{ zd}4BHdS>?H-2A77#m`G$mRDApYwKS(zHM%8?|lEUyZ3Yd;Md{rKSzJ@S{6hA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+^P)glzuW;soON! zto7rfztKjtA2+LTW#aDoXyQZ7eH~EnmY)Ff>nf%LRP5*RV3sCxWM8~uKZI$k_`AOR zsk?rV~e!T!t{ z^dEj=uzjOMQA<_87R)bQc=PuUrY&`0ljIZciP@DpX&sil|> zV6h+c1gB$pm>s<`1tkL8gS2%!@eZHnxX8!Mwiypym9Z| zC}g!l)EZ9a6peyI&*?-O9#n!*f*TlIQFk@Z>FF90u?Eq_{{*m63Nj z>92FwIccC22|b-dp0fQQQl@{(B|jydzlYgR!;xjIk%N!KQgcoG(K{DLhm%`}$I{#! zCqu@f*~_eCs*IQx;G<2HnheBr&4kyP3iWKXj3&woZ`q2l#+o9-wX1cD^>T=_l;kTW7{al~eKIL?v>kNN! zC!K~-)>GWBHz+ZyJM$@;xy7Wl@T=%#-Ch%H(X#pSp?7GS_j31`uWeI(qPO@ycG90s z9s9k1sb#A?Q{DNu%BiSN&(wxrkYDE{>~1ap1F{xu;iyY>uK&H8_DE+$ofSUi{{YXo BhCKiP literal 0 HcmV?d00001 diff --git a/meta/popsearch.meta.js b/meta/popsearch.meta.js index d7d517e..781b677 100644 --- a/meta/popsearch.meta.js +++ b/meta/popsearch.meta.js @@ -3,7 +3,7 @@ // @name:zh Popup Search: 快捷搜索 // @author lkytal // @namespace Lkytal -// @version 5.1.5 +// @version 5.2.0 // @icon https://github.com/lkytal/GM/raw/master/icons/search.png // @homepage https://lkytal.github.io/ // @homepageURL https://lkytal.github.io/GM diff --git a/popsearch.user.js b/popsearch.user.js index ffadf10..5211a64 100644 --- a/popsearch.user.js +++ b/popsearch.user.js @@ -3,7 +3,7 @@ // @name:zh Popup Search: 快捷搜索 // @author lkytal // @namespace Lkytal -// @version 5.1.5 +// @version 5.2.0 // @icon https://github.com/lkytal/GM/raw/master/icons/search.png // @homepage https://lkytal.github.io/ // @homepageURL https://lkytal.github.io/GM @@ -48,6 +48,7 @@ var CopyText, InTextBox, OnEngine, OpenSet, + OpenUrl, PopupInit, PopupLoad, ReadOpt, @@ -161,14 +162,20 @@ popData = { id: "UserEngine", title: "Example of User Engine", description: "自定义引擎示例 / Example of user engine", - src: "http://lkytal.qiniudn.com/ic.ico", + src: "https://github.com/lkytal/GM/raw/master/icon/atom.png", href: "https://www.google.com/search?newwindow=1&safe=off&q=${text}" }, { - id: "UserEngine2", + id: "UserEngine_dataURL", title: "Example Engine use dataURL", description: "DataURL引擎示例 / Example Engine use dataURL", src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAA0SURBVDhPY/z//z8DKYAJShMNSNYAdRIjIyOEjwdAVNLNScgA7jysAUh7J41IDbROrQwMAOdoEhG0gLSFAAAAAElFTkSuQmCC", href: "https://www.google.com/search?q=${text}%20site:${domain}" + }, { + id: "UserEngine_function", + title: "Example of User Engine use function", + description: "function自定义引擎示例 / Example of user engine use function", + src: "https://github.com/lkytal/GM/raw/master/icon/atom.png", + function: "alert('action on ' + domain); OpenUrl(text);" }] }; @@ -368,25 +375,6 @@ fixPos = function (sel, e) { return $('#popupTip').css('margin-left', m_left - 20 - fix); }; -OnEngine = function (e) { - var link; - link = $(this).data('link'); - if (link.indexOf('javascript:') === 0) { - eval(link.slice('javascript:'.length)); - return false; - } - if (isChrome()) { - //log "chrome" - GM_openInTab(link, { - active: GetOpt("Focus_st") === 1 - }); - } else { - GM_openInTab(link, !GetOpt("Focus_st")); - } - hideBar(100); - return false; -}; - PopupInit = function () { var $DivBox, $icon, EngineList, engine, j, k, l, len, len1, len2, ref, ref1, ref2; $('#ShowUpBox').remove(); @@ -689,6 +677,29 @@ GetTextboxSelection = function () { return ""; }; +OpenUrl = function (link) { + if (isChrome()) { + //log "chrome" + return GM_openInTab(link, { + active: GetOpt("Focus_st") === 1 + }); + } else { + return GM_openInTab(link, !GetOpt("Focus_st")); + } +}; + +OnEngine = function (e) { + var link; + link = $(this).data('link'); + if (link.indexOf('javascript:') === 0) { + eval(link.slice('javascript:'.length)); + return false; + } + OpenUrl(link); + hideBar(100); + return false; +}; + ShowBar = function (event) { var do_timeout_hide, e, engine, j, k, l, len, len1, len2, paraList, ref, ref1, ref2, sel, setHref; hideBar(); @@ -729,10 +740,9 @@ ShowBar = function (event) { "\\${url}": location.href }; setHref = function (engine) { - var $engine, href, para, value; + var $engine, href, para, runFunction, value; $engine = $("#" + engine.id + "Icon"); if (engine.href != null) { - //log engine.id + " : " + engine.href href = engine.href; for (para in paraList) { if (!hasProp.call(paraList, para)) continue; @@ -745,6 +755,19 @@ ShowBar = function (event) { } else if (engine.action != null) { $engine.off('click'); return $engine.on('click', engine.action); + } else if (engine.function != null) { + log("func " + engine.id + " : " + engine.function); + runFunction = function (func) { + console.log(popData.rawText, popData.text, document.domain, location.url); + return Function('"use strict";return (' + func + ')')()(popData.rawText, popData.text, document.domain, location.url, OpenUrl); + }; + $engine.off('click'); + return $engine.on('click', function () { + // func.apply(null, [popData.rawText, popData.text, popData.domain, popData.url]) + runFunction("function action(rawText, text, domain, url, OpenUrl) {" + engine.function + "}"); + hideBar(100); + return false; + }); } else { return console.log('empty engine', engine); } @@ -832,7 +855,7 @@ OpenSet = function () { }; SettingWin = function () { - var chsJSON, engJSON, engine, engineOptionList, generateEngineOption, generateOption, item, j, len, option, optionList, ref; + var engine, engineOptionList, exampleJSON, generateEngineOption, generateOption, item, j, len, option, optionList, ref; addAdditionalCSS(); $('#popup_setting_bg').remove(); generateOption = function (option) { @@ -861,25 +884,8 @@ SettingWin = function () { } return results; }().join(' '); - engJSON = `[ - { - id: "UserEngine", - title: "Example Engine", - description: "Example of user-defined engine", - src: "http://lkytal.qiniudn.com/ic.ico", - href: "https://www.google.com/search?q=\${text}" - } -]`; - chsJSON = `[ - { - id: "UserEngine", - title: "Example Engine", - description: "自定义引擎示例", - src: "http://lkytal.qiniudn.com/ic.ico", - href: "https://www.google.com/search?q=\${text}" - } -]`; - $("body").append(``); + exampleJSON = JSON.stringify(popData.defaultEngines, null, 4); + $("body").append(``); $("#popup_setting_bg, #popup_help_bg").hide(); $("#tabs_box > .popup_tab").on("click", function (e) { $("#tabs_box > .popup_tab").removeClass("popup_selected");