|
@@ -42,145 +42,47 @@ export default (function () {
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
chrome.scripting.executeScript({
|
|
chrome.scripting.executeScript({
|
|
target: {tabId:tab.id,allFrames:false},
|
|
target: {tabId:tab.id,allFrames:false},
|
|
- func: () => info.selectionText
|
|
|
|
- }, txt => chrome.DynamicToolRunner({
|
|
|
|
- tool: 'json-format',
|
|
|
|
- withContent: txt[0]
|
|
|
|
|
|
+ args: [info.selectionText],
|
|
|
|
+ func: (text) => text
|
|
|
|
+ }, resp => chrome.DynamicToolRunner({
|
|
|
|
+ tool, withContent: resp[0].result
|
|
}));
|
|
}));
|
|
-
|
|
|
|
- // chrome.tabs.executeScript(tab.id, {
|
|
|
|
- // code: '(' + (function (pInfo) {
|
|
|
|
- // return pInfo.selectionText;
|
|
|
|
- // }).toString() + ')(' + JSON.stringify(info) + ')',
|
|
|
|
- // allFrames: false
|
|
|
|
- // }, function (txt) {
|
|
|
|
- // chrome.DynamicToolRunner({
|
|
|
|
- // tool: 'json-format',
|
|
|
|
- // withContent: txt[0]
|
|
|
|
- // });
|
|
|
|
- // });
|
|
|
|
};
|
|
};
|
|
break;
|
|
break;
|
|
|
|
|
|
case 'code-beautify':
|
|
case 'code-beautify':
|
|
case 'en-decode':
|
|
case 'en-decode':
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
- chrome.tabs.executeScript(tab.id, {
|
|
|
|
- code: '(' + (function (pInfo) {
|
|
|
|
- let linkUrl = pInfo.linkUrl;
|
|
|
|
- let pageUrl = pInfo.pageUrl;
|
|
|
|
- let imgUrl = pInfo.srcUrl;
|
|
|
|
- let selection = pInfo.selectionText;
|
|
|
|
-
|
|
|
|
- return linkUrl || imgUrl || selection || pageUrl;
|
|
|
|
- }).toString() + ')(' + JSON.stringify(info) + ')',
|
|
|
|
- allFrames: false
|
|
|
|
- }, function (txt) {
|
|
|
|
- chrome.DynamicToolRunner({
|
|
|
|
- withContent: txt[0],
|
|
|
|
- query: `tool=${tool}`
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ chrome.scripting.executeScript({
|
|
|
|
+ target: {tabId:tab.id,allFrames:false},
|
|
|
|
+ args: [info.linkUrl || info.srcUrl || info.selectionText || info.pageUrl],
|
|
|
|
+ func: (text) => text
|
|
|
|
+ }, resp => chrome.DynamicToolRunner({
|
|
|
|
+ tool, withContent: resp[0].result
|
|
|
|
+ }));
|
|
};
|
|
};
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'qr-code':
|
|
case 'qr-code':
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
- chrome.tabs.executeScript(tab.id, {
|
|
|
|
- code: '(' + (function (pInfo) {
|
|
|
|
- let linkUrl = pInfo.linkUrl;
|
|
|
|
- let pageUrl = pInfo.pageUrl;
|
|
|
|
- let imgUrl = pInfo.srcUrl;
|
|
|
|
- let selection = pInfo.selectionText;
|
|
|
|
-
|
|
|
|
- return linkUrl || imgUrl || selection || pageUrl;
|
|
|
|
- }).toString() + ')(' + JSON.stringify(info) + ')',
|
|
|
|
- allFrames: false
|
|
|
|
- }, function (txt) {
|
|
|
|
- chrome.DynamicToolRunner({
|
|
|
|
- withContent: txt[0],
|
|
|
|
- query: `tool=qr-code`
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+ chrome.scripting.executeScript({
|
|
|
|
+ target: {tabId:tab.id,allFrames:false},
|
|
|
|
+ args: [info.linkUrl || info.srcUrl || info.selectionText || info.pageUrl],
|
|
|
|
+ func: (text) => text
|
|
|
|
+ }, resp => chrome.DynamicToolRunner({
|
|
|
|
+ tool, withContent: resp[0].result
|
|
|
|
+ }));
|
|
};
|
|
};
|
|
toolMap[tool].menuConfig[1].onClick = function (info, tab) {
|
|
toolMap[tool].menuConfig[1].onClick = function (info, tab) {
|
|
-
|
|
|
|
- // V2020.2.618之前的版本都用这个方法
|
|
|
|
- let funForLowerVer = function () {
|
|
|
|
- chrome.tabs.executeScript(tab.id, {
|
|
|
|
- code: '(' + (function (pInfo) {
|
|
|
|
- function loadImage(src) {
|
|
|
|
- return new Promise(resolve => {
|
|
|
|
- let image = new Image();
|
|
|
|
- image.setAttribute('crossOrigin', 'Anonymous');
|
|
|
|
- image.src = src;
|
|
|
|
- image.onload = function () {
|
|
|
|
- let width = this.naturalWidth;
|
|
|
|
- let height = this.naturalHeight;
|
|
|
|
- let canvas = document.createElement('canvas');
|
|
|
|
- canvas.style.cssText = 'position:absolute;top:-10000px;left:-10000px';
|
|
|
|
- document.body.appendChild(canvas);
|
|
|
|
- canvas.setAttribute('id', 'qr-canvas');
|
|
|
|
- canvas.height = height + 100;
|
|
|
|
- canvas.width = width + 100;
|
|
|
|
- let context = canvas.getContext('2d');
|
|
|
|
- context.fillStyle = 'rgb(255,255,255)';
|
|
|
|
- context.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
- context.drawImage(image, 0, 0, width, height, 50, 50, width, height);
|
|
|
|
- resolve(canvas.toDataURL());
|
|
|
|
- };
|
|
|
|
- image.onerror = function () {
|
|
|
|
- resolve(src);
|
|
|
|
- };
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let tempDataUrl = '__TEMP_DATA_URL_FOR_QRDECODE_';
|
|
|
|
- loadImage(pInfo.srcUrl).then(dataUrl => {
|
|
|
|
- window[tempDataUrl] = dataUrl;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return tempDataUrl;
|
|
|
|
-
|
|
|
|
- }).toString() + ')(' + JSON.stringify(info) + ')',
|
|
|
|
- allFrames: false
|
|
|
|
- }, function (resp) {
|
|
|
|
- let tempDataUrl = resp[0];
|
|
|
|
- let intervalId = -1;
|
|
|
|
- let repeatTime = 0;
|
|
|
|
- let loop = function () {
|
|
|
|
- repeatTime++;
|
|
|
|
- intervalId = setInterval(function () {
|
|
|
|
- chrome.tabs.executeScript(tab.id, {
|
|
|
|
- code: '(' + (function (tempDataUrl) {
|
|
|
|
- return window[tempDataUrl];
|
|
|
|
- }).toString() + ')(' + JSON.stringify(tempDataUrl) + ')',
|
|
|
|
- allFrames: false
|
|
|
|
- }, function (arr) {
|
|
|
|
- if (arr[0] === null && repeatTime <= 10) {
|
|
|
|
- loop();
|
|
|
|
- } else {
|
|
|
|
- clearInterval(intervalId);
|
|
|
|
- chrome.DynamicToolRunner({
|
|
|
|
- withContent: arr[0] || info.srcUrl,
|
|
|
|
- query: `tool=qr-code&mode=decode`
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }, 200);
|
|
|
|
- };
|
|
|
|
- loop();
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- chrome.tabs.executeScript(tab.id, {
|
|
|
|
- code: '(' + (function (pInfo) {
|
|
|
|
|
|
+ chrome.scripting.executeScript({
|
|
|
|
+ target: {tabId:tab.id,allFrames:false},
|
|
|
|
+ args: [info.srcUrl],
|
|
|
|
+ func: (text) => {
|
|
try {
|
|
try {
|
|
if (typeof window.qrcodeContentScript === 'function') {
|
|
if (typeof window.qrcodeContentScript === 'function') {
|
|
let qrcode = window.qrcodeContentScript();
|
|
let qrcode = window.qrcodeContentScript();
|
|
if (typeof qrcode.decode === 'function') {
|
|
if (typeof qrcode.decode === 'function') {
|
|
- // 直接解码
|
|
|
|
qrcode.decode(pInfo.srcUrl);
|
|
qrcode.decode(pInfo.srcUrl);
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
@@ -188,22 +90,16 @@ export default (function () {
|
|
} catch (e) {
|
|
} catch (e) {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
- }).toString() + ')(' + JSON.stringify(info) + ')',
|
|
|
|
- allFrames: false
|
|
|
|
- }, function (resp) {
|
|
|
|
- (resp[0] === 0) && funForLowerVer();
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
-
|
|
|
|
};
|
|
};
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
toolMap[tool].menuConfig[0].onClick = function (info, tab) {
|
|
chrome.DynamicToolRunner({
|
|
chrome.DynamicToolRunner({
|
|
- withContent: tool === 'image-base64' ? info.srcUrl : '',
|
|
|
|
- query: `tool=${tool}`
|
|
|
|
- });
|
|
|
|
|
|
+ tool, withContent: tool === 'image-base64' ? info.srcUrl : ''
|
|
|
|
+ })
|
|
};
|
|
};
|
|
break;
|
|
break;
|
|
}
|
|
}
|