From 4ee18d43264738d1614d91eb0fbc9ed3b21464f3 Mon Sep 17 00:00:00 2001 From: anhtai9710 <97306673+anhtai9710@users.noreply.github.com> Date: Sun, 29 Sep 2024 06:09:19 +0700 Subject: [PATCH 1/2] Update Easy offline pikpak.user.js --- Easy offline/Easy offline pikpak.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easy offline/Easy offline pikpak.user.js b/Easy offline/Easy offline pikpak.user.js index 8550d395dc0..df0a0b349de 100644 --- a/Easy offline/Easy offline pikpak.user.js +++ b/Easy offline/Easy offline pikpak.user.js @@ -1,4 +1,4 @@ -// ==UserScript== + // ==UserScript== // @name Easy Offline pikpak addon // @namespace hoothin // @version 2024-08-16 From 2219ee51be1651b4b4141460b5d4d02a4a8424bc Mon Sep 17 00:00:00 2001 From: anhtai9710 <97306673+anhtai9710@users.noreply.github.com> Date: Sun, 29 Sep 2024 06:11:33 +0700 Subject: [PATCH 2/2] Update Picviewer CE+.user.js --- Picviewer CE+/Picviewer CE+.user.js | 2000 +-------------------------- 1 file changed, 1 insertion(+), 1999 deletions(-) diff --git a/Picviewer CE+/Picviewer CE+.user.js b/Picviewer CE+/Picviewer CE+.user.js index 0af8b71fa83..b1630a73287 100644 --- a/Picviewer CE+/Picviewer CE+.user.js +++ b/Picviewer CE+/Picviewer CE+.user.js @@ -24856,2002 +24856,4 @@ ImgOps | https://imgops.com/#b#`; found = true; break; } else if (prefs.floatBar.listenBg && hasBg(checkEle)) { - let src = targetBg, nsrc = src, noActual = true, type = "scale"; - result = { - src: nsrc, - type: type, - imgSrc: src, - noActual:noActual, - img: checkEle - }; - found = true; - break; - } - } - } - if (!found && target.children && target.children[0] && target.children[0].nodeName.toUpperCase() == 'IMG') { - let img = target.children[0]; - while (img.nextElementSibling && img.nextElementSibling.nodeName.toUpperCase() == 'IMG') { - img = img.nextElementSibling; - } - let rect = img.getBoundingClientRect(); - - if (clientY >= rect.top && clientY <= rect.bottom && clientX >= rect.left && clientX <= rect.right) { - target = img; - found = true; - } - } - if (!found && document.elementsFromPoint) { - let elements = document.elementsFromPoint(clientX, clientY); - let checkLen = Math.min(elements.length, 5); - for (let i = 0; i < checkLen; i++) { - let ele = elements[i]; - if (!ele) continue; - if (/^img$/i.test(ele.nodeName)) { - target = ele; - result = null; - found = true; - break; - } else if (prefs.floatBar.listenBg && hasBg(ele)) { - target = ele; - let src = targetBg, nsrc = src, noActual = true, type = "scale"; - result = { - src: nsrc, - type: type, - imgSrc: src, - noActual:noActual, - img: target - }; - found = true; - break; - } else if (ele.nodeName.toUpperCase() == 'CANVAS') { - let src = ele.src || ele.dataset.src; - if (src) { - target = ele; - let nsrc = src, noActual = true, type = "scale"; - result = { - src: nsrc, - type: type, - imgSrc: src, - noActual:noActual, - img: target - }; - found = true; - break; - } - } - } - } - if (!found && target.shadowRoot) { - let imgs = target.shadowRoot.querySelectorAll('img'); - if (imgs.length === 1) target = imgs[0]; - } - if (result && !/^data:/i.test(result.src)) { - if (matchedRule.rules.length > 0 && target.nodeName.toUpperCase() != 'IMG') { - let src = result.src, img = {src: src}, type, imgSrc = src; - try { - let imgPN=target; - let imgPA,imgPE=[]; - while(imgPN=imgPN.parentElement){ - if(imgPN.nodeName.toUpperCase()=='A'){ - imgPA=imgPN; - break; - } - } - imgPN=target; - while(imgPN=imgPN.parentElement){ - if(imgPN.nodeName.toUpperCase()=='BODY'){ - break; - }else{ - imgPE.push(imgPN); - } - } - let newSrc = matchedRule.getImage(img, imgPA, imgPE, target); - if (newSrc && imgSrc != newSrc) { - let srcs, description; - src = newSrc; - if (Array.isArray(src)) { - srcs = src; - src = srcs.shift(); - } - type = 'rule'; - - if (matchedRule.description) { - let desc = matchedRule.description, attr; - if (Array.isArray(desc) && desc.length === 2) { - attr = desc[1]; - desc = desc[0]; - } - var node = getElementMix(desc, img); - if (node) { - description = attr ? node.getAttribute(attr) : (node.getAttribute('title') || node.textContent); - } - } - result.src = src; - result.type = type; - result.noActual = false; - result.xhr = matchedRule.xhr; - result.description = description || ''; - } - } catch(err) {} - if (result.type != "rule") { - tprules.find(function(rule, index, array) { - try { - src = rule.call(img); - if (src) { - return true; - }; - } catch(err) { - } - }); - if (src && src != imgSrc) { - result.src = src; - result.type = "tpRule"; - result.noActual = false; - } - } - } - } - } - } - var checkUniqueImgWin = function() { - if (canPreview) { - if (result.type != "link" && result.type != "rule" && result.src == result.imgSrc) { - if (result.imgAS.w <= result.imgCS.w && result.imgAS.h <= result.imgCS.h) { - if (result.img && result.img.childElementCount) return false; - var wSize = getWindowSize(); - if (result.imgAS.w <= wSize.w && result.imgAS.h <= wSize.h) return false; - } - } - uniqueImgWinInitX = clientX; - uniqueImgWinInitY = clientY; - if (uniqueImgWin && !uniqueImgWin.removed) { - if (uniqueImgWin.src == result.src) return true; - uniqueImgWin.remove(); - } - waitUntilMove(_target, () => { - new LoadingAnimC(result, 'popup', prefs.waitImgLoad, prefs.framesPicOpenInTopWindow); - }); - return true; - } else { - return false; - } - }; - - if (!result && target.nodeName.toUpperCase() != 'IMG') { - if (selectionClientRect && - clientX > selectionClientRect.left && - clientX < selectionClientRect.left + selectionClientRect.width && - clientY > selectionClientRect.top && - clientY < selectionClientRect.top + selectionClientRect.height) { - result = { - src: selectionStr, - type: "link", - imgSrc: selectionStr, - noActual:true, - img: target - }; - checkUniqueImgWin(); - return; - } - - - if (target.nodeName.toUpperCase() == 'A' && imageReg.test(target.href)) { - } else if (target.parentNode && target.parentNode.nodeName.toUpperCase() == 'A' && imageReg.test(target.parentNode.href)) { - target = target.parentNode; - } else { - target = null; - } - if (target) { - let src = target.href; - if (/[&\?]url\=/.test(src)) { - src = src.replace(/.*[&\?]url\=(.*?)(&.*|$)/, "$1"); - try { - src = decodeURIComponent(src); - } catch (e) {} - } - result = { - src: src, - type: "link", - imgSrc: src, - noActual:true, - img: target, - description: target.title - }; - checkUniqueImgWin(); - } - return; - } - - let sizeHide = false; - if (!result) { - pretreatment(target) - result = findPic(target); - if (!result) return; - } - - if (result) { - if (!result.imgAS && !result.imgCS) { - let sizeInfo = { - w: result.img.offsetWidth || result.img.scrollWidth || target.offsetWidth || target.scrollWidth, - h: result.img.offsetHeight || result.img.scrollHeight || target.offsetHeight || target.scrollHeight - } - result.imgAS = sizeInfo; - result.imgCS = sizeInfo; - } - if (prefs.floatBar.showWithRules && result.type == "rule") { - } else if (!(result.imgAS.w == result.imgCS.w && result.imgAS.h == result.imgCS.h)) {//如果不是两者完全相等,那么被缩放了. - if (prefs.floatBar.sizeLimitOr) { - if (result.imgCS.h <= prefs.floatBar.minSizeLimit.h && result.imgCS.w <= prefs.floatBar.minSizeLimit.w) {//最小限定判断. - sizeHide = true; - } - }else{ - if (result.imgCS.h <= prefs.floatBar.minSizeLimit.h || result.imgCS.w <= prefs.floatBar.minSizeLimit.w) {//最小限定判断. - sizeHide = true; - } - } - } else { - if (prefs.floatBar.sizeLimitOr) { - if (result.imgCS.w <= prefs.floatBar.forceShow.size.w && result.imgCS.h <= prefs.floatBar.forceShow.size.h) { - sizeHide = true; - } - } else { - if (result.imgCS.w <= prefs.floatBar.forceShow.size.w || result.imgCS.h <= prefs.floatBar.forceShow.size.h) { - sizeHide = true; - } - } - } - debug(result); - if (!result.noActual) { - if (!result.srcs) { - result.srcs = [result.imgSrc]; - } else { - if (result.imgSrc && result.srcs.join(" ").indexOf(result.imgSrc) == -1) { - result.srcs.push(result.imgSrc); - } - } - } - if (!floatBar) { - floatBar = new FloatBarC(); - } - if (result.type == 'rule' && matchedRule.clickToOpen && matchedRule.clickToOpen.enabled) { - if (canclePreCTO) {//取消上次的,防止一次点击打开多张图片 - canclePreCTO(); - } - canclePreCTO = clickToOpen(result); - } - - let hide = sizeHide || (prefs.floatBar.position == "hide" ? !altKey : altKey); - result.hide = hide; - let canShow = floatBar.start(result); - if (!checkUniqueImgWin() && canShow) { - if (floatBar.floatBar.style.opacity == 0) { - floatBar.floatBar.style.opacity = ""; - } - floatBar.floatBar.style.display = "initial"; - } - } - } - - var checkFloatBarTimer, initMouse = false; - function globalMouseoverHandler(e) { - if (galleryMode) return;//库模式全屏中...... - if (e.target == ImgWindowC.overlayer) return; - let canPreview = checkPreview(e); - if (e.type == "mousemove") { - if (!initMouse) { - initMouse = true; - return; - } - if ((uniqueImgWin && !uniqueImgWin.removed && !uniqueImgWin.previewed)) { - if (canPreview) { - uniqueImgWinInitX = e.clientX; - uniqueImgWinInitY = e.clientY; - uniqueImgWin.followPos(uniqueImgWinInitX, uniqueImgWinInitY); - } else { - uniqueImgWin.remove(); - } - return; - } else { - if (!canPreview) return; - let target = e.target; - if (target.nodeName.toUpperCase() == "PICTURE"){ - target = target.querySelector("img") || target; - } - if (target.nodeName.toUpperCase() != 'IMG') return; - } - } - if (!initMouse) return; - clearTimeout(checkFloatBarTimer); - checkFloatBarTimer = setTimeout(function() { - if (!e || !e.target || !e.target.parentNode) return; - if (gallery && gallery.shown) return; - checkFloatBar(e.target, e.type, canPreview, e.clientX, e.clientY, e.altKey); - }, 50); - } - - var selectionClientRect, selectionStr, selectionChanging = false; - document.addEventListener('selectionchange', e => { - if (selectionChanging) return; - selectionChanging = true; - setTimeout(() => { - selectionChanging = false; - const selection = window.getSelection(); - selectionStr = selection.toString(); - if (selectionStr && selectionStr.length < 500 && imageReg.test(selectionStr)) { - const range = selection.getRangeAt(0); - selectionClientRect = range.getBoundingClientRect(); - } else { - selectionClientRect = null; - } - }, 300); - }); - - document.addEventListener('visibilitychange', e => { - initMouse = false; - }); - - async function input(sel, v) { - await new Promise((resolve) => { - let checkInv = setInterval(() => { - let input = document.querySelector(sel); - if (input) { - input.focus(); - input.scrollIntoView(); - let lastValue = input.value; - if (input.nodeName == "INPUT") { - var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set; - nativeInputValueSetter.call(input, v); - } else { - var nativeTextareaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set; - nativeTextareaValueSetter.call(input, v); - } - let event = new Event('focus', { bubbles: true }); - input.dispatchEvent(event); - event = new Event('input', { bubbles: true }); - let tracker = input._valueTracker; - if (tracker) { - tracker.setValue(lastValue); - } - input.dispatchEvent(event); - event = new Event('change', { bubbles: true }); - input.dispatchEvent(event); - clearInterval(checkInv); - resolve(); - } - }, 100); - }); - } - - function emuClick(btn){ - if(!PointerEvent)return btn.click(); - let eventParam={ - isTrusted: true, - altKey: false, - azimuthAngle: 0, - bubbles: true, - button: 0, - buttons: 0, - clientX: 1, - clientY: 1, - cancelBubble: false, - cancelable: true, - composed: true, - ctrlKey: false, - defaultPrevented: false, - detail: 1, - eventPhase: 2, - fromElement: null, - height: 1, - isPrimary: false, - metaKey: false, - pointerId: 1, - pointerType: "mouse", - pressure: 0, - relatedTarget: null, - returnValue: true, - shiftKey: false, - toElement: null, - twist: 0, - which: 1 - }; - btn.focus(); - var mouseclick = new PointerEvent("mouseover",eventParam); - btn.dispatchEvent(mouseclick); - mouseclick = new PointerEvent("pointerover",eventParam); - btn.dispatchEvent(mouseclick); - mouseclick = new PointerEvent("mousedown",eventParam); - btn.dispatchEvent(mouseclick); - mouseclick = new PointerEvent("pointerdown",eventParam); - btn.dispatchEvent(mouseclick); - mouseclick = new PointerEvent("mouseup",eventParam); - btn.dispatchEvent(mouseclick); - mouseclick = new PointerEvent("pointerup",eventParam); - btn.dispatchEvent(mouseclick); - btn.click(); - } - - async function clickEle(sel, failAction) { - await new Promise((resolve) => { - let checkInv = setInterval(() => { - let ele = document.querySelector(sel); - if (ele) { - clearInterval(checkInv); - emuClick(ele); - resolve(); - }else if(failAction) { - failAction(); - } - }, 100); - }); - } - - async function sleep(time) { - await new Promise((resolve) => { - setTimeout(() => { - resolve(); - }, time); - }) - } - - function isKeyDownEffectiveTarget(target) { - var localName = (target.shadowRoot ? (target.shadowRoot.activeElement || target) : target).localName; - - // 确保光标不是定位在文字输入框或选择框 - if (localName == 'textarea' || localName == 'input' || localName == 'select'){ - return false; - } - - // 视频播放器 - if (localName == 'object' || localName == 'embed'){ - return false; - } - - // 百度贴吧回复输入的问题 - if (target.getAttribute('contenteditable') == 'true'){ - return false; - } - - return true; - } - - async function openGallery(){ - if(!gallery){ - gallery=new GalleryC(); - gallery.data=[]; - } - var allData=await gallery.getAllValidImgs(); - if(allData.length<1)return; - gallery.data=allData; - gallery.load(gallery.data); - return gallery; - } - - function getActiveElement(root) { - const activeEl = root.activeElement; - if (!activeEl) { - return null; - } - if (activeEl.shadowRoot) { - return getActiveElement(activeEl.shadowRoot); - } else { - return activeEl; - } - } - - function inputActive(doc) { - let activeEl = getActiveElement(doc); - if (activeEl && - ((/INPUT|TEXTAREA/i.test(activeEl.nodeName) && - activeEl.getAttribute("aria-readonly") != "true" - ) || - activeEl.contentEditable == 'true' - ) - ) { - return true; - } else { - while (activeEl && activeEl.nodeName) { - if (activeEl.contentEditable == 'true') return true; - if (activeEl.nodeName.toUpperCase() == 'BODY') { - break; - } - activeEl = activeEl.parentNode; - } - } - return false; - } - - function keydown(event) { - - //if (ImgWindowC.showing) return; - if (gallery && gallery.shown) return; - if (inputActive(document)) { - return; - } - var key = event.key; - if(checkGlobalKeydown(event)){ - if(prefs.floatBar.keys.enable && key==prefs.floatBar.keys.gallery){ - openGallery(); - event.stopPropagation(); - event.preventDefault(); - globalFuncEnabled = !globalFuncEnabled; - return true; - }else if((!gallery || (!gallery.shown && !gallery.minimized)) && prefs.floatBar.globalkeys.type == "press"){ - globalFuncEnabled = !globalFuncEnabled; - return true; - } - } - if (!prefs.floatBar.keys.enable){ - return false; - } - - if (event) { - if (event.ctrlKey || event.metaKey) return false; - if ((event.altKey || event.shiftKey) && window.getSelection().toString()) return false; - } - if (floatBar && isKeyDownEffectiveTarget(event.target)) { - Object.keys(prefs.floatBar.keys).some(function(action) { - if (action == 'enable' || action == 'search') return; - if (key == prefs.floatBar.keys[action]) { - floatBar.open(event, action); - event.preventDefault(); - return true; - } - }); - } - } - - function keyup(event) { - let isFuncKey = !event.isTrusted || event.key == 'Alt' || event.key == 'Control' || event.key == 'Meta'; - if(isFuncKey && (prefs.floatBar.globalkeys.type == "hold" || !checkPreview(event)) && (uniqueImgWin && !uniqueImgWin.removed)){ - clearTimeout(checkFloatBarTimer); - if(prefs.floatBar.globalkeys.closeAfterPreview){ - if (uniqueImgWin) { - uniqueImgWin.remove(); - } - }else{ - uniqueImgWin.focus(); - uniqueImgWin.imgWindow.classList.remove("pv-pic-window-transition-all"); - uniqueImgWin.imgWindow.classList.remove("preview"); - uniqueImgWin.previewed=true; - uniqueImgWin = null; - } - } - } - - function createEleFromJson(json) { - let collection = document.createDocumentFragment(); - json.forEach(data => { - let ele = document.createElement(data.node); - if (data.text) { - ele.innerText = data.text; - } - if (data.attr) { - Object.keys(data.attr).forEach(key => { - ele.setAttribute(key, data.attr[key]); - }); - } - if (data.children) { - let children = createEleFromJson(data.children); - ele.appendChild(children); - } - collection.appendChild(ele); - }); - return collection; - } - - window.addEventListener('message', handleMessage, true); - - addPageScript(); - - document.addEventListener('keyup', keyup, false); - document.addEventListener('mouseenter', globalMouseoverHandler, true); - document.addEventListener('mousemove', globalMouseoverHandler, true); - - document.addEventListener('mouseout',e=>{ - if (e.relatedTarget == ImgWindowC.overlayer) return; - if(uniqueImgWin && !uniqueImgWin.removed){ - if(checkPreview(e)){ - let showArea=uniqueImgWin.data.img.getBoundingClientRect(); - if(e.clientX < showArea.left + 20 || - e.clientX > showArea.right - 20 || - e.clientY < showArea.top + 20 || - e.clientY > showArea.bottom - 20){ - uniqueImgWin && uniqueImgWin.remove(); - } - } - } - }, true); - var editSitesFunc={ - "Lunapic": (src, initOpen) => { - _GM_openInTab('https://www.lunapic.com/editor/index.php?action=url&url=' + src, {active:true}); - }, - "Pixlr easy": async (src, initOpen) => { - if(initOpen){ - storage.setItem("editUrl", src); - _GM_openInTab('https://pixlr.com/x/', {active:true}); - }else{ - storage.setItem("editUrl", ""); - if(/^https:\/\/pixlr\.com\//.test(location.href)){ - await sleep(1000); - await clickEle('#splash-file-menu'); - await clickEle('#splash-file-url'); - await input('#image-url', src); - await clickEle('.dialog>.buttons>a.button.positive'); - } - } - }, - "Pixlr advanced": async (src, initOpen) => { - if(initOpen){ - storage.setItem("editUrl", src); - _GM_openInTab('https://pixlr.com/e/', {active:true}); - }else{ - storage.setItem("editUrl", ""); - if(/^https:\/\/pixlr\.com\//.test(location.href)){ - await sleep(1000); - await clickEle('#splash-file-menu'); - await clickEle('#splash-file-url'); - await input('#image-url', src); - await clickEle('.dialog>.buttons>a.button.positive'); - } - } - }, - "Photopea": async (src, initOpen) => { - if(initOpen){ - storage.setItem("editUrl", src); - _GM_openInTab('https://www.photopea.com/', {active:true}); - }else{ - storage.setItem("editUrl", ""); - if(/^https:\/\/www\.photopea\.com\//.test(location.href)){ - await sleep(1000); - await clickEle('.topbar>span>button'); - await clickEle('.cmanager>.contextpanel>div:nth-child(4)'); - await clickEle('.cmanager>div:last-child>div:nth-child(3)'); - await input('span.fitem.tinput>input', src); - await clickEle('.form>button'); - } - } - } - }; - var editSitesName={}; - for(let key in editSitesFunc){ - editSitesName[key]=key; - } - var newsInited = false, newsNode = null; - - initLang(); - var customLangOption={ - 'auto': i18n("defaultLang") - }; - for(let key in langList){ - customLangOption[key]=langList[key]; - } - GM_config.init({ - id: 'pv-prefs', - title: GM_config.create('a', { - href: 'https://greasyfork.org/scripts/24204-picviewer-ce', - target: '_blank', - textContent: 'Picviewer CE+ '+i18n("config"), - title: i18n("openHomePage") - }), - isTabs: true, - skin: 'tab', - frameStyle: { - minWidth: "350px", - width: ((visualLength((i18n("floatBar") + i18n("magnifier") + i18n("gallery") + i18n("imgWindow") + i18n("others")),"14px","arial,tahoma,myriad pro,sans-serif") + 250) || 480) + 'px', - zIndex:'2147483648', - margin: '1px', - border: '2px solid rgb(0, 0, 0)' - }, - css: [ - "#pv-prefs input[type='text'] { width: 50px; } ", - "#pv-prefs input[type='number'] { width: 50px; } ", - "#pv-prefs .inline .config_var { margin-left: 6px; }", - "#pv-prefs label.size { width: 205px; }", - "#pv-prefs span.sep-x { margin-left: 0px !important; }", - "#pv-prefs label.sep-x { margin-right: 5px; }", - "#pv-prefs label.floatBar-key { margin-left: 20px; width: 100px; }", - "#pv-prefs input.color { width: 120px; }", - "#pv-prefs input.order { width: 250px; }", - "#pv-prefs .config_header>a { border-bottom: solid 2px; }", - "#pv-prefs a:hover { color: #9f9f9f; }", - "#pv-prefs a { color: black; }", - "#pv-prefs .section_header_holder { padding-right: 10px; }", - "#pv-prefs textarea { width: 100%; }", - "#pv-prefs .nav-tabs { white-space: nowrap; width: fit-content; max-width: 100%; margin: 20 auto; display: flex; overflow-x: auto; overflow-y: visible; }", - ].join('\n'), - fields: { - // 浮动工具栏 - 'floatBar.position': { - label: i18n("position"), - title: i18n("positionTips"), - type: 'select', - options: { - 'top left': i18n("topLeft"), - 'top right': i18n("topRight"), - 'bottom right': i18n("bottomRight"), - 'bottom left': i18n("bottomLeft"), - 'top center': i18n("topCenter"), - 'bottom center': i18n("bottomCenter"), - 'hide': i18n("hide") - }, - "default": prefs.floatBar.position, - section: [i18n("floatBar")], - }, - 'floatBar.stayOut': { - label: i18n("stayOut"), - type: 'checkbox', - "default": prefs.floatBar.stayOut, - line: 'start' - }, - 'floatBar.stayOutOffsetX': { - label: 'X:', - type: 'int', - "default": prefs.floatBar.stayOutOffsetX - }, - 'floatBar.stayOutOffsetY': { - label: 'Y:', - type: 'int', - "default": prefs.floatBar.stayOutOffsetY, - after: ' '+i18n("px"), - line: 'end' - }, - 'floatBar.showDelay': { - label: i18n("showDelay"), - type: 'int', - "default": prefs.floatBar.showDelay, - after: ' '+i18n("ms"), - }, - 'floatBar.hideDelay': { - label: i18n("hideDelay"), - type: 'int', - className: 'hideDelay', - "default": prefs.floatBar.hideDelay, - after: ' '+i18n("ms") - }, - 'floatBar.forceShow.size.w': { - label: i18n("forceShow"), - type: 'int', - className: 'size', - "default": prefs.floatBar.forceShow.size.w, - title: i18n("forceShowTip"), - line: 'start', - }, - 'floatBar.forceShow.size.h': { - label: ' x ', - type: 'int', - className: 'sep-x', - after: ' '+i18n("px"), - "default": prefs.floatBar.forceShow.size.h, - line: 'end', - }, - 'floatBar.minSizeLimit.w': { - label: i18n("minSizeLimit"), - type: 'int', - className: 'size', - "default": prefs.floatBar.minSizeLimit.w, - title: i18n("minSizeLimitTip"), - line: 'start', - }, - 'floatBar.minSizeLimit.h': { - label: ' x ', - type: 'int', - className: 'sep-x', - after: ' '+i18n("px"), - "default": prefs.floatBar.minSizeLimit.h, - line: 'end', - }, - 'floatBar.sizeLimitOr': { - label: i18n("sizeLimitOr"), - type: "checkbox", - "default": false - }, - 'floatBar.showWithRules': { - label: i18n("showWithRules"), - type: "checkbox", - "default": prefs.floatBar.showWithRules, - title: i18n("showWithRulesTip"), - }, - 'floatBar.butonOrder': { - label: i18n("butonOrder"), - type: 'text', - className: 'order', - title: 'actual,current,gallery,magnifier,download', - "default": prefs.floatBar.butonOrder.join(', '), - }, - 'floatBar.additionalFeature': { - label: i18n("additionalFeature"), - type: 'select', - options: { - 'copy': i18n("copy"), - 'copyImg': i18n("copyImg"), - 'open': i18n("openInNewTab") - }, - "default": prefs.floatBar.additionalFeature || 'open' - }, - 'floatBar.invertAdditionalFeature': { - label: i18n("invertAdditionalFeature"), - type: 'checkbox', - "default": prefs.floatBar.invertAdditionalFeature - }, - 'floatBar.listenBg': { - label: i18n("listenBg"), - type: 'checkbox', - "default": prefs.floatBar.listenBg, - title: i18n("listenBgTip") - }, - 'floatBar.globalkeys.ctrl': { - label: i18n("globalkeys"), - type: 'checkbox', - after: "CTRL +", - "default": true, - line: 'start' - }, - 'floatBar.globalkeys.alt': { - after: "ALT +", - type: 'checkbox', - className: 'sep-x', - "default": false, - }, - 'floatBar.globalkeys.shift': { - after: "SHIFT +", - type: 'checkbox', - className: 'sep-x', - "default": false, - }, - 'floatBar.globalkeys.command': { - after: "META", - type: 'checkbox', - className: 'sep-x', - "default": false, - line: 'end', - }, - 'floatBar.globalkeys.type': { - label: i18n("globalkeysType"), - type: 'select', - options: { - 'press': i18n("globalkeysPress"), - 'hold': i18n("globalkeysHold") - }, - "default": prefs.floatBar.globalkeys.type - }, - 'floatBar.globalkeys.invertInitShow': { - label: i18n("initShow"), - type: 'checkbox', - "default": prefs.floatBar.globalkeys.invertInitShow - }, - 'floatBar.globalkeys.closeAfterPreview': { - label: i18n("closeAfterPreview"), - type: 'checkbox', - "default": prefs.floatBar.globalkeys.closeAfterPreview - }, - 'floatBar.previewMaxSizeW': { - label: i18n("previewMaxSize"), - type: 'int', - className: 'size', - "default": prefs.previewMaxSizeW || 0, - title: i18n("previewMaxSizeTip"), - line: 'start', - }, - 'floatBar.previewMaxSizeH': { - label: ' x ', - type: 'int', - className: 'sep-x', - after: ' '+i18n("px"), - "default": prefs.previewMaxSizeH || 0, - line: 'end', - }, - 'floatBar.globalkeys.previewFollowMouse': { - label: i18n("previewFollowMouse"), - type: 'checkbox', - "default": prefs.floatBar.globalkeys.previewFollowMouse - }, - // 按键 - 'floatBar.keys.enable': { - label: i18n("keysEnable"), - type: 'checkbox', - "default": prefs.floatBar.keys.enable - }, - 'floatBar.keys.actual': { - label: i18n("keysActual"), - type: 'text', - className: 'floatBar-key', - "default": prefs.floatBar.keys.actual, - title: i18n("keysActualTip") - }, - /*'floatBar.keys.search': { - label: i18n("keysSearch"), - type: 'text', - className: 'floatBar-key', - "default": prefs.floatBar.keys.search, - title: i18n("keysSearchTip") - },*/ - 'floatBar.keys.current': { - label: i18n("keysCurrent"), - type: 'text', - className: 'floatBar-key', - "default": prefs.floatBar.keys.current, - title: i18n("keysCurrentTip") - }, - 'floatBar.keys.magnifier': { - label: i18n("keysMagnifier"), - type: 'text', - className: 'floatBar-key', - "default": prefs.floatBar.keys.magnifier, - title: i18n("keysMagnifierTip") - }, - 'floatBar.keys.gallery': { - label: i18n("keysGallery"), - type: 'text', - className: 'floatBar-key', - "default": prefs.floatBar.keys.gallery, - title: i18n("keysGalleryTip") - }, - 'floatBar.keys.download': { - label: i18n("download"), - type: 'text', - className: 'floatBar-key', - "default": prefs.floatBar.keys.download - }, - 'floatBar.disableKeySites': { - label: i18n("disableKeySites"), - type: 'textarea', - "default": prefs.floatBar.disableKeySites - }, - - // 放大镜 - 'magnifier.radius': { - label: i18n("magnifierRadius"), - type: 'int', - "default": prefs.magnifier.radius, - section: [i18n("magnifier")], - after: ' '+i18n("px") - }, - 'magnifier.wheelZoom.enabled': { - label: i18n("magnifierWheelZoomEnabled"), - type: 'checkbox', - "default": prefs.magnifier.wheelZoom.enabled, - }, - 'magnifier.wheelZoom.scaleImage': { - label: i18n("magnifierScaleImage"), - type: 'checkbox', - "default": prefs.magnifier.wheelZoom.scaleImage !== false, - }, - 'magnifier.wheelZoom.ctrl': { - label: '', - type: 'checkbox', - after: "CTRL +", - "default": false, - line: 'start' - }, - 'magnifier.wheelZoom.alt': { - after: "ALT +", - type: 'checkbox', - className: 'sep-x', - "default": false, - }, - 'magnifier.wheelZoom.shift': { - after: "SHIFT +", - type: 'checkbox', - className: 'sep-x', - "default": false, - }, - 'magnifier.wheelZoom.meta': { - after: "META", - type: 'checkbox', - className: 'sep-x', - "default": false, - line: 'end', - }, - 'magnifier.wheelZoom.range': { - label: i18n("magnifierWheelZoomRange"), - type: 'textarea', - "default": prefs.magnifier.wheelZoom.range.join(', '), - }, - - // 图库 - 'gallery.defaultSizeLimit.w': { - label: i18n("defaultSizeLimit"), - type: 'int', - className: 'size', - section: [i18n("gallery")], - "default": prefs.gallery.defaultSizeLimit.w, - line: 'start', - }, - 'gallery.defaultSizeLimit.h': { - label: ' x ', - type: 'int', - className: 'sep-x', - after: ' '+i18n("px"), - "default": prefs.gallery.defaultSizeLimit.h, - line: 'end', - }, - 'gallery.fitToScreen': { - label: i18n("galleryFitToScreen"), - type: 'checkbox', - "default": prefs.gallery.fitToScreen, - title: i18n("galleryFitToScreenTip"), - line: 'start', - }, - 'gallery.fitToScreenSmall': { - label: i18n("galleryFitToScreenSmall"), - type: 'checkbox', - "default": prefs.gallery.fitToScreenSmall, - line: 'end', - }, - 'gallery.scrollEndToChange': { - label: i18n("galleryScrollEndToChange"), - type: 'checkbox', - "default": prefs.gallery.scrollEndToChange, - title: i18n("galleryScrollEndToChangeTip") - }, - 'gallery.backgroundColor': { - label: i18n("backgroundColor"), - type: 'text', - className: 'color', - "default": prefs.gallery.backgroundColor || 'rgba(20,20,20,0.75)', - line: 'end' - }, - 'gallery.exportType': { - label: i18n("galleryExportType"), - type: 'select', - options: { - 'grid': i18n("grid"), - 'gridBig': i18n("gridBig"), - 'list': i18n("list") - }, - "default": prefs.gallery.exportType, - }, - 'gallery.loadMore': { - label: i18n("galleryAutoLoad"), - type: 'checkbox', - "default": prefs.gallery.loadMore - }, - 'gallery.loadAll': { - label: i18n("galleryLoadAll"), - type: 'checkbox', - "default": prefs.gallery.loadAll, - title: i18n("galleryLoadAllTip") - }, - 'gallery.viewmoreEndless': { - label: i18n("viewmoreEndless"), - type: 'checkbox', - "default": prefs.gallery.viewmoreEndless - }, - 'gallery.downloadWithZip': { - label: i18n("galleryDownloadWithZip"), - type: 'checkbox', - "default": prefs.gallery.downloadWithZip - }, - 'gallery.downloadGap': { - label: i18n("galleryDownloadGap"), - type: 'int', - "default": prefs.gallery.downloadGap, - after: ' ms', - }, - 'gallery.formatConversion': { - label: i18n("formatConversion"), - type: 'textarea', - title: 'webp>png\nx-icon>png', - "default": prefs.gallery.formatConversion || '' - }, - 'gallery.aria2Host': { - label: i18n("aria2Host"), - type: 'text', - className: 'order', - "default": prefs.gallery.aria2Host || 'http://localhost:6800' - }, - 'gallery.aria2Token': { - label: i18n("aria2Token"), - type: 'text', - "default": prefs.gallery.aria2Token || '' - }, - 'gallery.scaleSmallSize': { - label: i18n("galleryScaleSmallSize1"), - type: 'int', - "default": prefs.gallery.scaleSmallSize, - after: i18n("galleryScaleSmallSize2") - }, - 'gallery.showSmallSize':{ - label: i18n("galleryShowSmallSize"), - type: 'checkbox', - "default": prefs.gallery.showSmallSize - }, - 'gallery.transition': { - label: i18n("galleryTransition"), - type: 'checkbox', - "default": prefs.gallery.transition - }, - 'gallery.disableArrow': { - label: i18n("galleryDisableArrow"), - type: 'checkbox', - "default": prefs.gallery.disableArrow - }, - 'gallery.sidebarPosition': { - label: i18n("gallerySidebarPosition"), - type: 'select', - options: { - 'bottom': i18n("bottom"), - 'right': i18n("right"), - 'left': i18n("left"), - 'top': i18n("top") - }, - "default": prefs.gallery.sidebarPosition, - line: 'start', - }, - 'gallery.sidebarSize': { - label: i18n("gallerySidebarSize"), - type: 'int', - "default": prefs.gallery.sidebarSize, - title: i18n("gallerySidebarSizeTip"), - after: ' '+i18n("px"), - line: 'end', - }, - 'gallery.max': { - label: i18n("galleryMax1"), - type: 'number', - "default": prefs.gallery.max, - after: i18n("galleryMax2") - }, - 'gallery.autoZoom': { - label: i18n("galleryAutoZoom"), - type: 'checkbox', - "default": prefs.gallery.autoZoom, - title: i18n("galleryAutoZoomTip") - }, - 'gallery.descriptionLength': { - label: i18n("galleryDescriptionLength1"), - type: 'int', - "default": prefs.gallery.descriptionLength, - after: i18n("galleryDescriptionLength2") - }, - 'gallery.autoOpenViewmore': { - label: i18n("autoOpenViewmore"), - type: 'checkbox', - "default": prefs.gallery.autoOpenViewmore - }, - 'gallery.autoOpenSites': { - label: i18n("galleryAutoOpenSites"), - type: 'textarea', - "default": prefs.gallery.autoOpenSites - }, - 'gallery.searchData': { - label: i18n("gallerySearchData"), - type: 'textarea', - "default": prefs.gallery.searchData - }, - 'gallery.editSite': { - label: i18n("galleryEditSite"), - type: 'select', - options: editSitesName, - "default": prefs.gallery.editSite, - }, - - // 图片窗口 - 'imgWindow.fitToScreen': { - label: i18n("imgWindowFitToScreen"), - type: 'checkbox', - "default": prefs.imgWindow.fitToScreen, - section: [i18n("imgWindow")], - title: i18n("imgWindowFitToScreenTip"), - }, - 'imgWindow.fitToScreenSmall': { - label: i18n("imgWindowFitToScreenWhenSmall"), - type: 'checkbox', - "default": prefs.imgWindow.fitToScreenSmall - }, - 'imgWindow.suitLongImg': { - label: i18n("suitLongImg"), - type: 'checkbox', - "default": prefs.imgWindow.suitLongImg - }, - 'imgWindow.switchStoreLoc': { - label: i18n("switchStoreLoc"), - type: 'checkbox', - "default": prefs.imgWindow.switchStoreLoc - }, - 'imgWindow.defaultTool': { - label: i18n("imgWindowDefaultTool"), - type: 'select', - options: { - 'hand': i18n("hand"), - 'rotate': i18n("rotate"), - 'zoom': i18n("zoom"), - }, - "default": prefs.imgWindow.defaultTool, - }, - 'imgWindow.close.escKey': { - label: i18n("imgWindowEscKey"), - type: 'checkbox', - "default": prefs.imgWindow.close.escKey, - line: 'start', - }, - 'imgWindow.close.dblClickImgWindow': { - label: i18n("imgWindowDblClickImgWindow"), - type: 'checkbox', - "default": prefs.imgWindow.close.dblClickImgWindow, - }, - 'imgWindow.close.clickOutside': { - label: i18n("imgWindowClickOutside"), - type: 'select', - options: { - '': i18n("none"), - 'click': i18n("click"), - 'dblclick': i18n("dblclick"), - }, - "default": prefs.imgWindow.close.clickOutside, - title: i18n("imgWindowClickOutsideTip"), - line: 'end', - }, - 'imgWindow.backgroundColor': { - label: i18n("backgroundColor"), - type: 'text', - className: 'color', - "default": prefs.imgWindow.backgroundColor, - line: 'end' - }, - 'imgWindow.overlayer.shown': { - label: i18n("imgWindowOverlayerShown"), - type: 'checkbox', - "default": prefs.imgWindow.overlayer.shown, - line: 'start', - }, - 'imgWindow.overlayer.color': { - label: i18n("imgWindowOverlayerColor"), - type: 'text', - className: 'color', - "default": prefs.imgWindow.overlayer.color, - line: 'end' - }, - 'imgWindow.shiftRotateStep': { - label: i18n("imgWindowShiftRotateStep1"), - type: 'int', - "default": prefs.imgWindow.shiftRotateStep, - after: i18n("imgWindowShiftRotateStep2") - }, - 'imgWindow.zoom.mouseWheelZoom': { - label: i18n("imgWindowMouseWheelZoom"), - type: 'checkbox', - "default": prefs.imgWindow.zoom.mouseWheelZoom, - }, - 'imgWindow.zoom.range': { - label: i18n("imgWindowZoomRange"), - type: 'textarea', - "default": prefs.imgWindow.zoom.range.join(', '), - title: i18n("imgWindowZoomRangeTip"), - attr: { - "spellcheck": "false" - } - }, - 'imgWindow.fixed': { - label: i18n("positionFixed"), - "default": prefs.imgWindow.fixed, - type: 'checkbox', - }, - 'imgWindow.zIndex': { - label: "z-Index", - "default": prefs.imgWindow.zIndex, - type: 'int', - }, - - // 其它 - 'waitImgLoad': { - label: i18n("waitImgLoad"), - type: 'checkbox', - "default": prefs.waitImgLoad, - section: [i18n("others")], - title: i18n("waitImgLoadTip") - }, - 'customLang': { - label: i18n("customLang"), - type: 'select', - options: customLangOption, - "default": prefs.customLang, - line: 'end', - }, - 'saveName': { - label: i18n("saveName"), - type: 'select', - options: { - 0: i18n("default"), - 1: i18n("textFirst"), - 2: i18n("onlyUrl"), - 3: i18n("urlAndText") - }, - "default": (prefs.saveName || 0), - title: i18n("saveNameTip"), - }, - 'saveNameAddTitle': { - label: i18n("saveNameAddTitle"), - type: 'checkbox', - "default": !!prefs.saveNameAddTitle - }, - 'debug': { - label: i18n("debug"), - type: 'checkbox', - "default": prefs.debug - }, - 'customRules': { - label: GM_config.create('a', { - href: 'https://github.com/hoothin/UserScripts/tree/master/Picviewer%20CE%2B#-custom-rules-example', - target: '_blank', - textContent: i18n("customRules") - }), - type: 'textarea', - "default": prefs.customRules - } - /*'firstEngine': { - label: i18n("firstEngine"), - type: 'select', - options: { - "Tineye":"Tineye", - "Google":"Google", - "Baidu":"Baidu" - }, - "default": prefs.firstEngine, - },*/ - }, - events: { - open: async function(doc, win, frame) { - isConfigOpen = true; - let saveBtn = doc.querySelector("#"+this.id+"_saveBtn"); - let closeBtn = doc.querySelector("#"+this.id+"_closeBtn"); - let resetLink = doc.querySelector("#"+this.id+"_resetLink"); - let customInput = doc.querySelector("#"+this.id+"_field_customRules"); - customInput.style.height = "188px"; - customInput.setAttribute("spellcheck", "false"); - saveBtn.textContent = i18n("saveBtn"); - saveBtn.title = i18n("saveBtnTips"); - saveBtn.addEventListener('click', e => { - if (customInput.value) { - if (customInput.value.trim().indexOf("[") != 0) { - e.stopPropagation(); - e.preventDefault(); - alert("The rules must be enclosed in square brackets ([])."); - return; - } - try { - var customRules; - if (customInput.value.indexOf("name:") !== -1) { - if (!isunsafe()) { - unsafeWindow.eval(createScript(customInput.value)); - } - } else { - customInput.value = JSON.stringify(JSON.parse(customInput.value), null, 4); - } - } catch(err) { - e.stopPropagation(); - e.preventDefault(); - alert("Wrong rule:" + err.toString()); - } - } - }, true); - closeBtn.textContent=i18n("closeBtn"); - closeBtn.title=i18n("closeBtnTips"); - resetLink.textContent=i18n("resetLink"); - resetLink.title=i18n("resetLinkTips"); - let searchData=doc.getElementById(this.id+"_field_gallery.searchData"); - if(searchData && searchData.value==""){ - searchData.value=defaultSearchData; - } - let about = doc.getElementById(this.id + "_section_4"); - if (about) { - if (!newsNode) { - newsNode = document.createElement("div"); - let newsEles = createEleFromJson([ - { - node: "div", - text: "Made with ❤️ by @", - attr: { - style: "width: calc(100% - 8px); text-align: center;" - }, - children: [ - { - node: "a", - text: "Hoothin", - attr: { - "href": "mailto:rixixi@gmail.com" - } - }, - { - node: "br" - }, - { - node: "a", - text: "Star Me on 🐱Github", - attr: { - href: "https://github.com/hoothin/UserScripts", - target: "_blank" - } - }, - { - node: "br" - }, - { - node: "span", - text: "Join our " - }, - { - node: "a", - text: "Discord", - attr: { - href: "https://discord.com/invite/keqypXC6wD", - target: "_blank" - } - } - ] - }, - { - node: "img", - attr: { - src: "https://s2.loli.net/2023/02/06/afTMxeASm48z5vE.jpg", - style: "width: 100%; margin-top: 5px; max-height: 180px; display: none;", - onload: "this.style.display=''" - } - }, - { - node: "div", - attr: { - style: "width: 100%; display: flex; align-items: center; justify-content: center; margin-top: 5px; font-size: 14px;" - }, - children: [ - { - node: "img", - attr: { - src: "https://ko-fi.com/favicon-32x32.png", - style: "margin-right: 5px; height: 25px; display: none;", - onload: "this.style.display=''" - } - }, - { - node: "a", - text: "Ko-fi", - attr: { - href: "https://ko-fi.com/hoothin", - style: "margin-right: 10px;", - target: "_blank" - } - }, - { - node: "img", - attr: { - src: "https://static.afdiancdn.com/favicon.ico", - style: "margin-right: 5px; height: 20px; display: none;", - onload: "this.style.display=''" - } - }, - { - node: "a", - text: "爱发电", - attr: { - href: "https://afdian.com/@hoothin", - target: "_blank" - } - } - ] - } - ]); - newsNode.style.padding = "5px"; - newsNode.appendChild(newsEles); - about.appendChild(newsNode); - } - if (!newsInited) { - let news = await GM_fetch(`https://hoothin.com/scripts/pvcep/${lang}`).then(response => response.json()).catch(e => {}); - newsInited = true; - if (!news) return; - let newsEles = createEleFromJson(news); - if (newsEles && newsEles.childElementCount) { - if (newsNode) about.removeChild(newsNode); - newsNode = document.createElement("div"); - newsNode.appendChild(newsEles); - } - } - about.appendChild(newsNode); - } - }, - save: function() { - loadPrefs(); - storage.setItem("customLang", prefs.customLang); - }, - close: function() { - isConfigOpen = false; - } - } - }); - - - - loadPrefs(); - - var hideIcon=storage.getListItem("hideIcon", location.hostname) || false; - var hideIconStyle=document.createElement('style'); - hideIconStyle.textContent=`#pv-float-bar-container{display:none!important}`; - if(hideIcon){ - document.head.appendChild(hideIconStyle); - } - _GM_registerMenuCommand(i18n("openConfig"), openPrefs); - _GM_registerMenuCommand(i18n("openGallery"), openGallery); - _GM_registerMenuCommand(i18n("hideIcon") + (hideIcon ? "☑️" : ""), () => { - hideIcon=!hideIcon; - storage.setListItem("hideIcon", location.hostname, hideIcon); - if(hideIcon){ - document.head.appendChild(hideIconStyle); - }else{ - document.head.removeChild(hideIconStyle); - } - }); - _GM_registerMenuCommand(i18n("ruleRequest"), () => { - _GM_openInTab("https://github.com/hoothin/UserScripts/issues/new?labels=Picviewer%20CE%2B&template=custom-rule-request.md&title=Request%20Picviewer%20CE%2B%20support%20for%20" + location.hostname, {active:true}); - }); - - function initKeyInputs() { - if (!GM_config.frame || !GM_config.frame.contentDocument) return; - let keyInputs = GM_config.frame.contentDocument.querySelectorAll('input.floatBar-key'); - [].forEach.call(keyInputs, input => { - input.setAttribute('readOnly', 'readonly'); - input.addEventListener("keydown", e => { - if (e.key === 'Escape' || e.key === 'Backspace') input.value = ''; - else input.value = e.key; - e.stopPropagation(); - e.preventDefault(); - }); - }); - } - - matchedRule = getMatchedRule(); - let editUrl=storage.getItem("editUrl"); - if(editUrl){ - let editFunc=editSitesFunc[prefs.gallery.editSite]; - if(!editFunc)editFunc=editSitesFunc[Object.keys(editSitesFunc)[0]]; - if(editFunc){ - if (document.readyState == 'complete'){ - editFunc(editUrl); - }else{ - let readystatechangeHandler = e => { - if (document.readyState == 'complete') { - editFunc(editUrl); - document.removeEventListener('readystatechange', readystatechangeHandler); - } - }; - document.addEventListener('readystatechange', readystatechangeHandler); - } - } - } - - var configStyle = document.createElement("style"); - configStyle.textContent = "#pv-prefs { display: initial; }"; - configStyle.type = 'text/css'; - if (location.hostname == "hoothin.github.io" && location.pathname == "/UserScripts/Picviewer%20CE+/") { - openPrefs(); - } else if (location.hostname == "hoothin.github.io" && location.pathname == "/UserScripts/Picviewer%20CE+/gallery.html") { - let gallery = new GalleryC(); - gallery.data = []; - gallery.lockGallery = true; - var allData = await gallery.getAllValidImgs(); - gallery.data = allData; - gallery.load(gallery.data); - let searchParams = new URLSearchParams(location.search); - let viewMore = searchParams.get("mode"); - let imgs = searchParams.get("imgs"); - if (imgs) { - gallery.addImageUrls(imgs); - } - if (viewMore == "1") { - gallery.maximizeSidebar(); - } - let imgCon = gallery.eleMaps['img-content'], waitingDouble = false, openImageTimer; - imgCon.addEventListener('click', e => { - if (e.target == imgCon) { - clearTimeout(openImageTimer); - if (waitingDouble) { - waitingDouble = false; - gallery.openImages({altKey: true}); - return; - } - waitingDouble = true; - openImageTimer = setTimeout(() => { - waitingDouble = false; - gallery.openImages(e); - }, 300); - } - }, true); - } else if (prefs.gallery.autoOpenSites) { - let sitesArr=prefs.gallery.autoOpenSites.split("\n"); - for(let s=0;s { - if (!ruleImportUrlReg.test(location.href)) return; - if (/pre|code/i.test(e.target.nodeName)) { - let content = e.target.innerText.trim(); - if (/"name":/.test(content) && /"(r|xhr)":/.test(content)) { - try { - localStorage.setItem('picviewerCE.config.curTab', 4); - let webRule = JSON.parse(content.replace(/^\/\/.*/g, "")); - let customRules; - let fieldsCustomRules = GM_config.fields.customRules; - if (prefs.customRules.indexOf('"name":') !== -1) { - customRules = JSON.parse(prefs.customRules); - } else { - customRules = []; - } - customRules.push(webRule); - fieldsCustomRules.value = JSON.stringify(customRules, null, 4); - openPrefs(); - } catch (e) { - alert(e.toString()); - } - } - } - }, true); - } - - function openPrefs() { - let fieldsSearchData = GM_config.fields["gallery.searchData"]; - if (fieldsSearchData && fieldsSearchData.value) { - fieldsSearchData.value = fieldsSearchData.value.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&").replace(/>/g, ">").replace(/").replace(/</g, "<").replace(/&/g, "&").replace(/>/g, ">").replace(/{ - if (GM_config.frame && GM_config.frame.contentDocument.body.innerHTML === "") { - _GM_openInTab("https://hoothin.github.io/UserScripts/Picviewer%20CE+/", {active:true}); - return; - } - if (GM_config.frame && GM_config.frame.style && GM_config.frame.style.display == "none") { - GM_config.frame.src=""; - } - initKeyInputs(); - }, 1000); - } - - function loadPrefs() { - // 根据 GM_config 的 key 载入设置到 prefs - Object.keys(GM_config.fields).forEach(function(keyStr) { - var keys = keyStr.split('.'); - var lastKey = keys.pop(); - - var lastPref = prefs; - var curKey = keys.shift(); - while(curKey){ - lastPref = lastPref[curKey]; - curKey = keys.shift(); - } - - var value = GM_config.get(keyStr); - if (typeof value != 'undefined') { - // 特殊的 - if (keyStr == 'magnifier.wheelZoom.range' || keyStr == 'imgWindow.zoom.range') { - lastPref[lastKey] = value.split(/[,,]\s*/).map(function(s) { return parseFloat(s)}); - } else if(keyStr == 'floatBar.butonOrder') { - lastPref[lastKey] = value.trim().split(/\s*[,,]\s*/); - } else { - lastPref[lastKey] = value; - } - } - }); - try { - if (localStorage && localStorage.setItem) { - if (!storage.getItem('inited')) { - localStorage.setItem('picviewerCE.config.curTab', 4); - storage.setItem('inited', true); - } - } - } catch(e) {} - if (typeof prefs.gallery.formatConversion == 'undefined') { - prefs.gallery.formatConversion = "webp>png"; - } - prefs.gallery.formatConversion.split("\n").forEach(str => { - let pair = str.split(">"); - if (pair.length !== 2) return; - formatDict.set(pair[0].trim(), pair[1].trim()); - }); - - debug = prefs.debug ? console.log.bind(console) : function() {}; - } - - }; - - function drawTobase64(img){ - canvas.width = img.naturalWidth || img.width; - canvas.height = img.naturalHeight || img.height; - let ctx = canvas.getContext('2d'); - ctx.clearRect(0, 0, canvas.width, canvas.height); - ctx.drawImage(img, 0, 0); - return canvas.toDataURL("image/png"); - } - - function init2(){ - init(topObject,window,document,arrayFn,envir,storage,unsafeWindow); - }; - - - //大致检测运行环境 - var envir={ - ie:typeof document.documentMode == 'number', - firefox:typeof XPCNativeWrapper == 'function', - opera:!!window.opera, - chrome:!!window.chrome, - }; - - //ie的话,不支持 < ie9的版本 - if(envir.ie && document.documentMode < 9){ - return; - }; - - - var arrayFn=(function(){ - var arrayProto=Array.prototype; - return { - find:arrayProto.find, - slice:arrayProto.slice, - forEach:arrayProto.forEach, - some:arrayProto.some, - every:arrayProto.every, - map:arrayProto.map, - filter:arrayProto.filter, - indexOf:arrayProto.indexOf, - lastIndexOf:arrayProto.lastIndexOf, - }; - - })(); - - var storage={ - supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',//chrome的gm函数式空函数 - mxAppStorage:(function(){//傲游扩展储存接口 - try{ - return window.external.mxGetRuntime().storage; - }catch(e){ - }; - })(), - operaUJSStorage:(function(){//opera userjs全局存储接口 - try{ - return window.opera.scriptStorage; - }catch(e){ - }; - })(), - setItem:function(key,value){ - if (this.supportGM) { - GM_setValue(key, value); - if (value === "" && typeof GM_deleteValue != 'undefined') { - GM_deleteValue(key); - } - } else if (this.operaUJSStorage) { - this.operaUJSStorage.setItem(key, value); - } else if (this.mxAppStorage) { - this.mxAppStorage.setConfig(key, value); - } else if (window.localStorage) { - window.localStorage.setItem(key, value); - } - }, - getItem:function(key){ - var value; - if(this.supportGM){ - value=GM_getValue(key); - }else if(this.operaUJSStorage){ - value=this.operaUJSStorage.getItem(key); - }else if(this.mxAppStorage){ - value=this.mxAppStorage.getConfig(key); - }else if(window.localStorage){ - value=window.localStorage.getItem(key); - }; - return value; - }, - getListItem: function(list, key) { - var value; - var listData = this.getItem(list); - if (listData) { - for(var i = 0; i < listData.length; i++) { - var data = listData[i]; - if (data.k == key) { - value = data.v; - break; - } - } - } - return value; - }, - setListItem: function(list, key, value, limitNum = 50) { - var listData = this.getItem(list); - if (!listData || !listData.filter) listData = []; - listData = listData.filter(data => data && data.k != key); - if (value) { - listData.unshift({k: key, v: value}); - if (listData.length > limitNum) listData.pop(); - } - this.setItem(list, listData); - } - }; - - function getUrl(url, callback, onError){ - _GM_xmlhttpRequest({ - method: 'GET', - url: url.trim(), - onload: callback, - onerror: onError - }); - } - - function setSearchState(words, imgState){ - if (imgState) imgState.innerHTML=createHTML(words); - } - - var searchSort=["Tineye","Google","Baidu"]; - function sortSearch(){ - for(var i=0;i2)break; - srcs.push(imgData.objURL); - } - setSearchState(i18n("findOverBeginLoad",["百度",srcs.length]),imgCon); - callBackFun(srcs); - }else{ - searchNext(); - return; - } - }, onError); - }; - var searchGoogle=function(){ - setSearchState(i18n("beginSearchImg","Google"),imgCon); - getUrl("https://www.google.com/searchbyimage?safe=off&image_url="+encodeURIComponent(imgSrc), function(d){ - let googleHtml=document.implementation.createHTMLDocument(''); - googleHtml.documentElement.innerHTML = d.responseText; - let sizeUrl=googleHtml.querySelector("div.card-section>div>div>span.gl>a"); - if(sizeUrl){ - getUrl("https://www.google.com"+sizeUrl.getAttribute("href"), function(d){ - googleHtml.documentElement.innerHTML = d.responseText; - let imgs=googleHtml.querySelectorAll("div.rg_meta"); - if(imgs.length==0){searchNext();return;} - srcs=[]; - for(var i=0;i2)break; - let jsonData=JSON.parse(imgs[i].innerHTML); - srcs.push(jsonData.ou); - } - setSearchState(i18n("findOverBeginLoad",["Google",srcs.length]),imgCon); - callBackFun(srcs); - }, onError); - }else{ - searchNext(); - } - }, onError); - }; - var searchTineye=function(){ - setSearchState(i18n("beginSearchImg","Tineye"),imgCon); - getUrl("https://www.tineye.com/search?url="+encodeURIComponent(imgSrc)+"&sort=size", function(d){ - let tineyeHtml=document.implementation.createHTMLDocument(''); - tineyeHtml.documentElement.innerHTML = d.responseText; - let searchImg=tineyeHtml.querySelectorAll(".match-details>div.match:first-of-type>p.image-link:first-of-type>a"); - if(searchImg.length>0){ - srcs=[]; - for(var i=0;i2)break; - srcs.push(searchImg[i].href); - } - setSearchState(i18n("findOverBeginLoad",["Tineye",srcs.length]),imgCon); - callBackFun(srcs); - }else{ - searchNext(); - } - }, onError); - }; - var searchNext=function(){ - searchFrom++; - if(searchFrom<=searchSort.length)switchSearch(); - else{ - if(noneResult)noneResult(); - setSearchState(i18n("findNoPic"),imgCon); - setTimeout(function(){ - setSearchState("",imgCon); - },2000); - } - }; - var callBackFun=function(srcs){ - callBack(srcs, searchFrom); - }; - if(!searchFrom)searchFrom=1; - var switchSearch=function(){ - switch(searchSort[searchFrom-1]){ - case "Baidu": - searchBaidu(); - break; - case "Google": - searchGoogle(); - break; - case "Tineye": - searchTineye(); - break; - default: - searchTineye(); - break; - } - }; - switchSearch(); - } - - if (window.top != window.self) { - if (window.self.innerWidth === 0 && window.self.innerHeight === 0) { - if (document.readyState !== "complete") { - window.addEventListener('load', e => { - setTimeout(() => { - if (window.self.innerWidth > 250 && window.self.innerHeight > 250) { - init2(); - } - }, 500); - }); - } - } else { - init2(); - } - } else { - init2(); - } - -})(this,window,document,(typeof unsafeWindow=='undefined'? window : unsafeWindow)); \ No newline at end of file + let src = targetBg, nsrc = src, noAct \ No newline at end of file