Skip to content

Commit

Permalink
Merge branch 'Stay-2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
shenruisi committed Jan 31, 2022
2 parents 40db5e6 + 6c584a8 commit cc991d9
Show file tree
Hide file tree
Showing 38 changed files with 1,289 additions and 187 deletions.
23 changes: 19 additions & 4 deletions Stay Extension/Resources/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ Date.prototype.dateFormat = function(fmt) {
let matchAppScriptList=[];
let matchAppScriptConsole = [];
let gm_console = {};

browser.runtime.onMessage.addListener((request, sender, sendResponse) => {

if ("bootstrap" == request.from || "iframe" == request.from){
if ("fetchScripts" == request.operate){
console.log("background---fetchScripts request==", request);
Expand Down Expand Up @@ -58,13 +60,17 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
else if ("gm-apis" == request.from){
if ("GM_error" == request.operate){
console.log("gm-apis GM_error, from exect catch, ",request);
gm_console[request.uuid] = [];
if (!gm_console[request.uuid]) {
gm_console[request.uuid] = [];
}
gm_console[request.uuid].push({ msg: request.message, msgType: "error", time: new Date().dateFormat()});
console.log("GM_error=",gm_console);
}
if ("GM_log" == request.operate){
console.log("gm-apis GM_log");
gm_console[request.uuid] = [];
if (!gm_console[request.uuid]){
gm_console[request.uuid] = [];
}
gm_console[request.uuid].push({ msg: request.message, msgType: "log", time: new Date().dateFormat() });
console.log("GM_log=",gm_console);
}
Expand Down Expand Up @@ -94,6 +100,7 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
}
}
else if ("popup" == request.from){
console.log(request.from + " " + request.operate);
if ("fetchLog" == request.operate){
sendResponse({ body: gm_console });
}
Expand Down Expand Up @@ -128,9 +135,17 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
}else{
sendResponse({ body: [] });
}

}
else if ("fetchRegisterMenuCommand" == request.operate){
browser.tabs.query({ active: true, currentWindow: true }, (tabs) => {
browser.tabs.sendMessage(tabs[0].id, { from : "background", operate: "fetchRegisterMenuCommand"});
});
}
else if ("execRegisterMenuCommand" == request.operate){
browser.tabs.query({ active: true, currentWindow: true }, (tabs) => {
browser.tabs.sendMessage(tabs[0].id, { from : "background", operate: "execRegisterMenuCommand", id:request.id, uuid:request.uuid});
});
}
return true;
}

});
19 changes: 12 additions & 7 deletions Stay Extension/Resources/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Main entrance of Stay
1. Fetch inject scripts from SafariWebExtensionHandler
2. Use @match, @include, @exclude to match the correct script with the url.
content.js passing message to background.js or popup.js using browser.runtime.sendMessage.
popup.js passing message to background.js using browser.runtime.sendMessage.
background.js passing message to content.js using browser.tabs.sendMessage.
popup.js passing message to content.js should sendMessage to background.js first.
*/
console.log("bootstrap inject");
var __b; if (typeof browser != "undefined") {__b = browser;} if (typeof chrome != "undefined") {__b = chrome;}
Expand Down Expand Up @@ -29,26 +34,26 @@ function matchRule(str, rule) {

const $_matchesCheck = (userLibraryScript,url) => {
let matched = false;
let matchPatternInBlock;
userLibraryScript.matches.forEach((match)=>{ //check matches
let matchPattern = new window.MatchPattern(match);
if (matchPattern.doMatch(url)){
matched = true;
matchPatternInBlock = matchPattern;
}
});
if (matched){
if (userLibraryScript.includes.length > 0){
matched = false;
userLibraryScript.includes.forEach((include)=>{
if (matchRule(url.href,include)){
matched = true;
if (matchPatternInBlock.doMatch(include)) {
matched = matchRule(url.href, include);
}
});
}


userLibraryScript.excludes.forEach((exclude)=>{
if (matchRule(url.href,exclude)){
matched = false;
if (matchPatternInBlock.doMatch(exclude)) {
matched = !matchRule(url.href, exclude);
}
});
}
Expand Down Expand Up @@ -86,7 +91,7 @@ async function start(){
}

if (script.active){ //inject active script
console.log("injectScript",script);
console.log("injectScript",script.content);
browser.runtime.sendMessage({
from: "bootstrap",
operate: "injectScript",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Stay Extension/Resources/images/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Stay Extension/Resources/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const langMessage = {
"en_US": {
"matched_scripts_tab": "Matched Scripts",
"console_tab": "Console",
"state_actived": "Activated",
"state_stopped": "Stopped",
"null_scripts": "no available scripts were matched",
"null_register_menu": "Do not apply to this web site",
"menu_close": "Close",
"toast_keep_active": "Please keep the script activated",
},
"zh_CN": {
"matched_scripts_tab": "已匹配脚本",
"console_tab": "控制台",
"state_actived": "运行中",
"state_stopped": "已停止",
"null_scripts": "未匹配到可用脚本",
"null_register_menu": "不应用于该网站",
"menu_close": "关闭",
"toast_keep_active": "请保持脚本处于激活状态",
},
"zh_HK": {
"matched_scripts_tab": "已匹配腳本",
"console_tab": "控制台",
"state_actived": "運行中",
"state_stopped": "已停止",
"null_scripts": "未匹配到可用腳本",
"null_register_menu": "不應用於該網站",
"menu_close": "關閉",
"toast_keep_active": "請保持腳本處於激活狀態",
},
}
Loading

0 comments on commit cc991d9

Please sign in to comment.