Deploying to gh-pages from @ fishjar/kiss-translator@7b6148302d 🚀

This commit is contained in:
fishjar
2023-09-09 12:18:01 +00:00
parent 14eeb58cdf
commit 186b56e6d2
7 changed files with 18 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name KISS Translator
// @namespace https://github.com/fishjar/kiss-translator
// @version 1.6.9
// @version 1.6.10
// @description A minimalist bilingual translation Extension & Greasemonkey Script (一个简约的双语网页翻译扩展 & 油猴脚本)
// @author Gabe<yugang2002@gmail.com>
// @homepageURL https://github.com/fishjar/kiss-translator
@@ -28540,7 +28540,7 @@ var DarkMode = __webpack_require__(45);
;// CONCATENATED MODULE: ./src/views/Options/DarkModeButton.js
function DarkModeButton(){var _useDarkMode=useDarkMode(),darkMode=_useDarkMode.darkMode,toggleDarkMode=_useDarkMode.toggleDarkMode;return/*#__PURE__*/(0,jsx_runtime.jsx)(IconButton_IconButton,{onClick:toggleDarkMode,color:"inherit",children:darkMode?/*#__PURE__*/(0,jsx_runtime.jsx)(LightMode/* default */.Z,{}):/*#__PURE__*/(0,jsx_runtime.jsx)(DarkMode/* default */.Z,{})});}
;// CONCATENATED MODULE: ./src/views/Popup/Header.js
function Header(_ref){var setShowPopup=_ref.setShowPopup;var handleHomepage=function handleHomepage(){window.open("https://github.com/fishjar/kiss-translator","_blank");};return/*#__PURE__*/(0,jsx_runtime.jsxs)(Stack_Stack,{direction:"row",justifyContent:"space-between",alignItems:"center",spacing:2,children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(Stack_Stack,{direction:"row",justifyContent:"flex-start",alignItems:"center",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(IconButton_IconButton,{onClick:handleHomepage,children:/*#__PURE__*/(0,jsx_runtime.jsx)(Home/* default */.Z,{})}),/*#__PURE__*/(0,jsx_runtime.jsx)(Box_Box,{children:"".concat("KISS Translator"," v").concat("1.6.9")})]}),setShowPopup?/*#__PURE__*/(0,jsx_runtime.jsx)(IconButton_IconButton,{onClick:function onClick(){setShowPopup(false);},children:/*#__PURE__*/(0,jsx_runtime.jsx)(Close/* default */.Z,{})}):/*#__PURE__*/(0,jsx_runtime.jsx)(DarkModeButton,{})]});}
function Header(_ref){var setShowPopup=_ref.setShowPopup;var handleHomepage=function handleHomepage(){window.open("https://github.com/fishjar/kiss-translator","_blank");};return/*#__PURE__*/(0,jsx_runtime.jsxs)(Stack_Stack,{direction:"row",justifyContent:"space-between",alignItems:"center",spacing:2,children:[/*#__PURE__*/(0,jsx_runtime.jsxs)(Stack_Stack,{direction:"row",justifyContent:"flex-start",alignItems:"center",children:[/*#__PURE__*/(0,jsx_runtime.jsx)(IconButton_IconButton,{onClick:handleHomepage,children:/*#__PURE__*/(0,jsx_runtime.jsx)(Home/* default */.Z,{})}),/*#__PURE__*/(0,jsx_runtime.jsx)(Box_Box,{children:"".concat("KISS Translator"," v").concat("1.6.10")})]}),setShowPopup?/*#__PURE__*/(0,jsx_runtime.jsx)(IconButton_IconButton,{onClick:function onClick(){setShowPopup(false);},children:/*#__PURE__*/(0,jsx_runtime.jsx)(Close/* default */.Z,{})}):/*#__PURE__*/(0,jsx_runtime.jsx)(DarkModeButton,{})]});}
;// CONCATENATED MODULE: ./src/libs/iframe.js
var isIframe=window.self!==window.top;var sendIframeMsg=function sendIframeMsg(action,args){document.querySelectorAll("iframe").forEach(function(iframe){iframe.contentWindow.postMessage({action:action,args:args},"*");});};
;// CONCATENATED MODULE: ./src/views/Popup/index.js
@@ -28562,7 +28562,7 @@ function Popup(_ref){var _ref2,_ref3;var setShowPopup=_ref.setShowPopup,tran=_re
;// CONCATENATED MODULE: ./src/views/Action/index.js
function Action(_ref){var _fab$x,_fab$y;var translator=_ref.translator,fab=_ref.fab;var fabWidth=40;var _useState=(0,react.useState)(false),_useState2=(0,slicedToArray/* default */.Z)(_useState,2),showPopup=_useState2[0],setShowPopup=_useState2[1];var _useState3=(0,react.useState)({w:window.innerWidth,h:window.innerHeight}),_useState4=(0,slicedToArray/* default */.Z)(_useState3,2),windowSize=_useState4[0],setWindowSize=_useState4[1];var _useState5=(0,react.useState)(false),_useState6=(0,slicedToArray/* default */.Z)(_useState5,2),moved=_useState6[0],setMoved=_useState6[1];var handleWindowResize=(0,react.useMemo)(function(){return debounce(function(){setWindowSize({w:window.innerWidth,h:window.innerHeight});});},[]);var handleWindowClick=function handleWindowClick(e){setShowPopup(false);};var handleStart=(0,react.useCallback)(function(){setMoved(false);},[]);var handleMove=(0,react.useCallback)(function(){setMoved(true);},[]);(0,react.useEffect)(function(){// 注册快捷键
var shortcuts=translator.setting.shortcuts||DEFAULT_SHORTCUTS;var clearShortcuts=[shortcutRegister(shortcuts[OPT_SHORTCUT_TRANSLATE],function(){translator.toggle();setShowPopup(false);}),shortcutRegister(shortcuts[OPT_SHORTCUT_STYLE],function(){translator.toggleStyle();setShowPopup(false);}),shortcutRegister(shortcuts[OPT_SHORTCUT_POPUP],function(){setShowPopup(function(pre){return!pre;});}),shortcutRegister(shortcuts[OPT_SHORTCUT_SETTING],function(){window.open("https://fishjar.github.io/kiss-translator/options.html","_blank");})];return function(){clearShortcuts.forEach(function(fn){fn();});};},[translator]);(0,react.useEffect)(function(){// 注册菜单
var menuCommandIds=[];if(isGm){try{menuCommandIds.push(GM.registerMenuCommand("Toggle Translate (Alt+q)",function(event){translator.toggle();setShowPopup(false);},"Q"),GM.registerMenuCommand("Toggle Style (Alt+c)",function(event){translator.toggleStyle();setShowPopup(false);},"C"),GM.registerMenuCommand("Open Menu (Alt+k)",function(event){setShowPopup(function(pre){return!pre;});},"K"),GM.registerMenuCommand("Open Setting (Alt+o)",function(event){setShowPopup(function(pre){return!pre;});},"O"));}catch(err){console.log("[registerMenuCommand]",err);}}return function(){if(isGm){try{menuCommandIds.forEach(function(id){GM.unregisterMenuCommand(id);});}catch(err){//
var menuCommandIds=[];if(isGm){try{menuCommandIds.push(GM.registerMenuCommand("Toggle Translate (Alt+q)",function(event){translator.toggle();setShowPopup(false);},"Q"),GM.registerMenuCommand("Toggle Style (Alt+c)",function(event){translator.toggleStyle();setShowPopup(false);},"C"),GM.registerMenuCommand("Open Menu (Alt+k)",function(event){setShowPopup(function(pre){return!pre;});},"K"),GM.registerMenuCommand("Open Setting (Alt+o)",function(event){window.open("https://fishjar.github.io/kiss-translator/options.html","_blank");},"O"));}catch(err){console.log("[registerMenuCommand]",err);}}return function(){if(isGm){try{menuCommandIds.forEach(function(id){GM.unregisterMenuCommand(id);});}catch(err){//
}}};},[translator]);(0,react.useEffect)(function(){window.addEventListener("resize",handleWindowResize);return function(){window.removeEventListener("resize",handleWindowResize);};},[handleWindowResize]);(0,react.useEffect)(function(){window.addEventListener("click",handleWindowClick);return function(){window.removeEventListener("click",handleWindowClick);};},[]);var popProps=(0,react.useMemo)(function(){var width=Math.min(windowSize.w,300);var height=Math.min(windowSize.h,442);var left=(windowSize.w-width)/2;var top=(windowSize.h-height)/2;return{windowSize:windowSize,width:width,height:height,left:left,top:top};},[windowSize]);var fabProps={windowSize:windowSize,width:fabWidth,height:fabWidth,left:(_fab$x=fab.x)!==null&&_fab$x!==void 0?_fab$x:0,top:(_fab$y=fab.y)!==null&&_fab$y!==void 0?_fab$y:windowSize.h/2};return/*#__PURE__*/(0,jsx_runtime.jsx)(SettingProvider,{children:/*#__PURE__*/(0,jsx_runtime.jsxs)(Theme,{children:[/*#__PURE__*/(0,jsx_runtime.jsx)(Draggable,_objectSpread2(_objectSpread2({},popProps),{},{show:showPopup,onStart:handleStart,onMove:handleMove,handler:/*#__PURE__*/(0,jsx_runtime.jsx)(Paper_Paper,{style:{cursor:"move"},elevation:3,children:/*#__PURE__*/(0,jsx_runtime.jsx)(Header,{setShowPopup:setShowPopup})}),children:/*#__PURE__*/(0,jsx_runtime.jsx)(Paper_Paper,{children:showPopup&&/*#__PURE__*/(0,jsx_runtime.jsx)(Popup,{setShowPopup:setShowPopup,translator:translator})})}),"pop"),/*#__PURE__*/(0,jsx_runtime.jsx)(Draggable,_objectSpread2(_objectSpread2({snapEdge:true},fabProps),{},{show:translator.setting.hideFab?false:!showPopup,onStart:handleStart,onMove:handleMove,handler:/*#__PURE__*/(0,jsx_runtime.jsx)(Fab_Fab,{size:"small",color:"primary",onClick:function onClick(e){if(!moved){setShowPopup(function(pre){return!pre;});}},children:/*#__PURE__*/(0,jsx_runtime.jsx)(Translate/* default */.Z,{})})}),"fab")]})});}
;// CONCATENATED MODULE: ./src/views/Content/LoadingIcon.js
function LoadingIcon(){return/*#__PURE__*/(0,jsx_runtime.jsxs)("svg",{viewBox:"0 0 100 100",style:{maxWidth:"1.2em",maxHeight:"1.2em"},children:[/*#__PURE__*/(0,jsx_runtime.jsx)("circle",{fill:DEFAULT_COLOR,stroke:"none",cx:"6",cy:"50",r:"6",children:/*#__PURE__*/(0,jsx_runtime.jsx)("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 15 ; 0 -15; 0 15",repeatCount:"indefinite",begin:"0.1"})}),/*#__PURE__*/(0,jsx_runtime.jsx)("circle",{fill:DEFAULT_COLOR,stroke:"none",cx:"30",cy:"50",r:"6",children:/*#__PURE__*/(0,jsx_runtime.jsx)("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 10 ; 0 -10; 0 10",repeatCount:"indefinite",begin:"0.2"})}),/*#__PURE__*/(0,jsx_runtime.jsx)("circle",{fill:DEFAULT_COLOR,stroke:"none",cx:"54",cy:"50",r:"6",children:/*#__PURE__*/(0,jsx_runtime.jsx)("animateTransform",{attributeName:"transform",dur:"1s",type:"translate",values:"0 5 ; 0 -5; 0 5",repeatCount:"indefinite",begin:"0.3"})})]});}
@@ -28655,7 +28655,7 @@ if(!(now-subRulesSyncAt>interval)){_context3.next=14;break;}_context3.next=12;re
var gm_ref;var MSG_GM_xmlHttpRequest="xmlHttpRequest";var MSG_GM_setValue="setValue";var MSG_GM_getValue="getValue";var MSG_GM_deleteValue="deleteValue";var MSG_GM_info="info";/**
* 注入页面的脚本请求并接受GM接口信息
* @param {*} param0
*/var injectScript=function injectScript(ping){window.APP_INFO={name:"KISS Translator",version:"1.6.9",eventName:ping};};/**
*/var injectScript=function injectScript(ping){window.APP_INFO={name:"KISS Translator",version:"1.6.10",eventName:ping};};/**
* 适配GM脚本
*/var adaptScript=function adaptScript(ping){var _getInfo;var promiseGM=function promiseGM(action,args){var timeout=arguments.length>2&&arguments[2]!==undefined?arguments[2]:5000;return new Promise(function(resolve,reject){var pong=genEventName();var handleEvent=function handleEvent(e){window.removeEventListener(pong,handleEvent);var _e$detail=e.detail,data=_e$detail.data,error=_e$detail.error;if(error){reject(new Error(error));}else{resolve(data);}};window.addEventListener(pong,handleEvent);window.dispatchEvent(new CustomEvent(ping,{detail:{action:action,args:args,pong:pong}}));setTimeout(function(){window.removeEventListener(pong,handleEvent);reject(new Error("timeout"));},timeout);});};window.KISS_GM={fetch:function fetch(input,init){return promiseGM(MSG_GM_xmlHttpRequest,{input:input,init:init});},setValue:function setValue(key,val){return promiseGM(MSG_GM_setValue,{key:key,val:val});},getValue:function getValue(key){return promiseGM(MSG_GM_getValue,{key:key});},deleteValue:function deleteValue(key){return promiseGM(MSG_GM_deleteValue,{key:key});},getInfo:function getInfo(){return(_getInfo=_getInfo||_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){return _regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(window.GM_info){_context.next=4;break;}_context.next=3;return promiseGM(MSG_GM_info);case 3:window.GM_info=_context.sent;case 4:return _context.abrupt("return",window.GM_info);case 5:case"end":return _context.stop();}},_callee);}))).apply(this,arguments);}};};/**
* 监听并回应页面对GM接口的请求
@@ -28698,7 +28698,7 @@ var webfix_ref,webfix_ref2,_webfix;/**
;// CONCATENATED MODULE: ./src/userscript.js
var userscript_ref;/**
* 入口函数
*/var init=function init(){return(userscript_ref=userscript_ref||asyncToGenerator_asyncToGenerator(/*#__PURE__*/regeneratorRuntime_regeneratorRuntime().mark(function _callee(){var _GM,_GM$info,_GM$info$script,_GM$info$script$grant,ping,script,href,setting,rules,rule,translator,fab,$action,shadowContainer,emotionRoot,shadowRootElement,cache;return regeneratorRuntime_regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(!(document.location.href.includes("http://localhost:3000/options.html")||document.location.href.includes("https://fishjar.github.io/kiss-translator/options.html")||document.location.href.includes("https://kiss-translator.rayjar.com/options"))){_context.next=3;break;}if((_GM=GM)!==null&&_GM!==void 0&&(_GM$info=_GM.info)!==null&&_GM$info!==void 0&&(_GM$info$script=_GM$info.script)!==null&&_GM$info$script!==void 0&&(_GM$info$script$grant=_GM$info$script.grant)!==null&&_GM$info$script$grant!==void 0&&_GM$info$script$grant.includes("unsafeWindow")){unsafeWindow.GM=GM;unsafeWindow.APP_INFO={name:"KISS Translator",version:"1.6.9"};}else{ping=utils_genEventName();window.addEventListener(ping,handlePing);// window.eval(`(${injectScript})("${ping}")`); // eslint-disable-line
*/var init=function init(){return(userscript_ref=userscript_ref||asyncToGenerator_asyncToGenerator(/*#__PURE__*/regeneratorRuntime_regeneratorRuntime().mark(function _callee(){var _GM,_GM$info,_GM$info$script,_GM$info$script$grant,ping,script,href,setting,rules,rule,translator,fab,$action,shadowContainer,emotionRoot,shadowRootElement,cache;return regeneratorRuntime_regeneratorRuntime().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(!(document.location.href.includes("http://localhost:3000/options.html")||document.location.href.includes("https://fishjar.github.io/kiss-translator/options.html")||document.location.href.includes("https://kiss-translator.rayjar.com/options"))){_context.next=3;break;}if((_GM=GM)!==null&&_GM!==void 0&&(_GM$info=_GM.info)!==null&&_GM$info!==void 0&&(_GM$info$script=_GM$info.script)!==null&&_GM$info$script!==void 0&&(_GM$info$script$grant=_GM$info$script.grant)!==null&&_GM$info$script$grant!==void 0&&_GM$info$script$grant.includes("unsafeWindow")){unsafeWindow.GM=GM;unsafeWindow.APP_INFO={name:"KISS Translator",version:"1.6.10"};}else{ping=utils_genEventName();window.addEventListener(ping,handlePing);// window.eval(`(${injectScript})("${ping}")`); // eslint-disable-line
script=document.createElement("script");script.textContent="(".concat(injectScript,")(\"").concat(ping,"\")");document.head.append(script);}return _context.abrupt("return");case 3:// 翻译页面
href=isIframe?document.referrer:document.location.href;_context.next=6;return getSettingWithDefault();case 6:setting=_context.sent;_context.next=9;return storage_getRulesWithDefault();case 9:rules=_context.sent;_context.next=12;return matchRule(rules,href,setting);case 12:rule=_context.sent;translator=new Translator(rule,setting);webfix(href,setting);if(!isIframe){_context.next=18;break;}// iframe
window.addEventListener("message",function(e){var _e$data;var action=e===null||e===void 0?void 0:(_e$data=e.data)===null||_e$data===void 0?void 0:_e$data.action;switch(action){case MSG_TRANS_TOGGLE:translator.toggle();break;case MSG_TRANS_PUTRULE:translator.updateRule(e.data.args||{});break;default:}});return _context.abrupt("return");case 18:_context.next=20;return getFabWithDefault();case 20:fab=_context.sent;$action=document.createElement("div");$action.setAttribute("id","kiss-translator");document.body.parentElement.appendChild($action);shadowContainer=$action.attachShadow({mode:"closed"});emotionRoot=document.createElement("style");shadowRootElement=document.createElement("div");shadowContainer.appendChild(emotionRoot);shadowContainer.appendChild(shadowRootElement);cache=(0,emotion_cache_browser_esm/* default */.Z)({key:"css",prepend:true,container:emotionRoot});client.createRoot(shadowRootElement).render(/*#__PURE__*/(0,jsx_runtime.jsx)(react.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(emotion_element_c39617d8_browser_esm.C,{value:cache,children:/*#__PURE__*/(0,jsx_runtime.jsx)(Action,{translator:translator,fab:fab})})}));// 同步订阅规则