fix iframe bug
This commit is contained in:
6
dist/userscript/kiss-translator.user.js
vendored
6
dist/userscript/kiss-translator.user.js
vendored
@@ -55174,11 +55174,11 @@ var span=document.createElement(APP_LCNAME);el.appendChild(span);var root=(0,cli
|
|||||||
* 自定义元素
|
* 自定义元素
|
||||||
*/var ActionElement=/*#__PURE__*/function(_HTMLElement){_inherits(ActionElement,_HTMLElement);var _super=_createSuper(ActionElement);function ActionElement(){classCallCheck_classCallCheck(this,ActionElement);return _super.apply(this,arguments);}createClass_createClass(ActionElement,[{key:"connectedCallback",value:function connectedCallback(){var shadowContainer=this.attachShadow({mode:"open"});var emotionRoot=document.createElement("style");var shadowRootElement=document.createElement("div");shadowContainer.appendChild(emotionRoot);shadowContainer.appendChild(shadowRootElement);var 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_Action,{})})}));}}]);return ActionElement;}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));/**
|
*/var ActionElement=/*#__PURE__*/function(_HTMLElement){_inherits(ActionElement,_HTMLElement);var _super=_createSuper(ActionElement);function ActionElement(){classCallCheck_classCallCheck(this,ActionElement);return _super.apply(this,arguments);}createClass_createClass(ActionElement,[{key:"connectedCallback",value:function connectedCallback(){var shadowContainer=this.attachShadow({mode:"open"});var emotionRoot=document.createElement("style");var shadowRootElement=document.createElement("div");shadowContainer.appendChild(emotionRoot);shadowContainer.appendChild(shadowRootElement);var 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_Action,{})})}));}}]);return ActionElement;}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));/**
|
||||||
* 入口函数
|
* 入口函数
|
||||||
*/asyncToGenerator_asyncToGenerator(/*#__PURE__*/regeneratorRuntime_regeneratorRuntime().mark(function _callee(){var root,actionName,$action,_yield$getSetting,fetchInterval,fetchLimit,rules,rule,translator;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"))){_context.next=4;break;}root=client.createRoot(document.getElementById("root"));root.render(/*#__PURE__*/(0,jsx_runtime.jsx)(react.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(Options,{})}));return _context.abrupt("return");case 4:// 插入按钮
|
*/asyncToGenerator_asyncToGenerator(/*#__PURE__*/regeneratorRuntime_regeneratorRuntime().mark(function _callee(){var root,actionName,$action,_yield$getSetting,fetchInterval,fetchLimit,rules,rule,translator;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"))){_context.next=4;break;}root=client.createRoot(document.getElementById("root"));root.render(/*#__PURE__*/(0,jsx_runtime.jsx)(react.StrictMode,{children:/*#__PURE__*/(0,jsx_runtime.jsx)(Options,{})}));return _context.abrupt("return");case 4:if(!(window.self!==window.top)){_context.next=6;break;}return _context.abrupt("return");case 6:// 插入按钮
|
||||||
actionName="kiss-action";customElements.define(actionName,ActionElement);$action=document.createElement(actionName);document.body.parentElement.appendChild($action);// 翻译页面
|
actionName="kiss-action";customElements.define(actionName,ActionElement);$action=document.createElement(actionName);document.body.parentElement.appendChild($action);// 翻译页面
|
||||||
_context.next=10;return getSetting();case 10:_yield$getSetting=_context.sent;fetchInterval=_yield$getSetting.fetchInterval;fetchLimit=_yield$getSetting.fetchLimit;transPool.update(fetchInterval,fetchLimit);_context.next=16;return getRules();case 16:rules=_context.sent;rule=matchRule(rules,document.location.href);translator=new Translator(rule);// 监听消息
|
_context.next=12;return getSetting();case 12:_yield$getSetting=_context.sent;fetchInterval=_yield$getSetting.fetchInterval;fetchLimit=_yield$getSetting.fetchLimit;transPool.update(fetchInterval,fetchLimit);_context.next=18;return getRules();case 18:rules=_context.sent;rule=matchRule(rules,document.location.href);translator=new Translator(rule);// 监听消息
|
||||||
window.addEventListener(EVENT_KISS,function(e){var _e$detail,_e$detail2;var action=e===null||e===void 0?void 0:(_e$detail=e.detail)===null||_e$detail===void 0?void 0:_e$detail.action;var args=(e===null||e===void 0?void 0:(_e$detail2=e.detail)===null||_e$detail2===void 0?void 0:_e$detail2.args)||{};switch(action){case MSG_TRANS_TOGGLE:translator.toggle();break;case MSG_TRANS_GETRULE:window.dispatchEvent(new CustomEvent(EVENT_KISS,{detail:{action:MSG_TRANS_CURRULE,args:translator.rule}}));break;case MSG_TRANS_PUTRULE:translator.updateRule(args);break;default:// console.log(`[entry] kissEvent action skip: ${action}`);
|
window.addEventListener(EVENT_KISS,function(e){var _e$detail,_e$detail2;var action=e===null||e===void 0?void 0:(_e$detail=e.detail)===null||_e$detail===void 0?void 0:_e$detail.action;var args=(e===null||e===void 0?void 0:(_e$detail2=e.detail)===null||_e$detail2===void 0?void 0:_e$detail2.args)||{};switch(action){case MSG_TRANS_TOGGLE:translator.toggle();break;case MSG_TRANS_GETRULE:window.dispatchEvent(new CustomEvent(EVENT_KISS,{detail:{action:MSG_TRANS_CURRULE,args:translator.rule}}));break;case MSG_TRANS_PUTRULE:translator.updateRule(args);break;default:// console.log(`[entry] kissEvent action skip: ${action}`);
|
||||||
}});case 20:case"end":return _context.stop();}},_callee);}))();
|
}});case 22:case"end":return _context.stop();}},_callee);}))();
|
||||||
}();
|
}();
|
||||||
/******/ })()
|
/******/ })()
|
||||||
;
|
;
|
||||||
@@ -62,6 +62,11 @@ class ActionElement extends HTMLElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// iframe
|
||||||
|
if (window.self !== window.top) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 插入按钮
|
// 插入按钮
|
||||||
const actionName = "kiss-action";
|
const actionName = "kiss-action";
|
||||||
customElements.define(actionName, ActionElement);
|
customElements.define(actionName, ActionElement);
|
||||||
@@ -97,7 +102,7 @@ class ActionElement extends HTMLElement {
|
|||||||
translator.updateRule(args);
|
translator.updateRule(args);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// console.log(`[entry] kissEvent action skip: ${action}`);
|
// console.log(`[entry] kissEvent action skip: ${action}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user