Skip to content

Commit

Permalink
把功能和标签分开,标签左键插件图标,功能右键插件图标
Browse files Browse the repository at this point in the history
  • Loading branch information
scoful committed Mar 20, 2020
1 parent cae2cf2 commit 3370620
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 152 deletions.
9 changes: 9 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,14 @@
},
"refresh": {
"message": "refresh"
},
"generateQr": {
"message": "url generate QrCode"
},
"tabsMenu": {
"message": "tabs menu"
},
"remindMenu": {
"message": "remind menu"
}
}
9 changes: 9 additions & 0 deletions _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,14 @@
},
"refresh": {
"message": "刷新"
},
"generateQr": {
"message": "网址生成二维码"
},
"tabsMenu": {
"message": "标签功能菜单"
},
"remindMenu": {
"message": "定时功能菜单"
}
}
1 change: 0 additions & 1 deletion css/popup.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.menu-entry {
text-align: center;
font-size: 100%;
background: #fefefe;
padding: 10px;
Expand Down
174 changes: 173 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ function remind(minute) {
// 时间到,清除定时器
clearTimeout(timeoutId);
surplusTime = undefined;
chrome.contextMenus.update("1", { title: `${chrome.i18n.getMessage("remindStatus")}` }, function callback() { })
}, minute * 60 * 1000);
var endDateStr = new Date();
var min = endDateStr.getMinutes();
Expand Down Expand Up @@ -1000,7 +1001,7 @@ function timeDown(endDateStr) {
timeoutId = setTimeout(function () {
timeDown(endDateStr);
}, 1000)

chrome.contextMenus.update("1", { title: surplusTime }, function callback() { })
}

// 判断是否int
Expand Down Expand Up @@ -1193,4 +1194,175 @@ chrome.storage.onChanged.addListener(function (changes, areaName) {
} else {
console.log("不要同步")
}
});


chrome.contextMenus.create({
id: "1",
title: `${chrome.i18n.getMessage("remindStatus")}`,
contexts: ["browser_action"]
});

chrome.contextMenus.create({
id: "2",
title: `${chrome.i18n.getMessage("generateQr")}`,
contexts: ["browser_action"],
onclick: function () {
chrome.tabs.query({ url: ["https://*/*", "http://*/*"], active: true, currentWindow: true }, function (tab) {
console.log(tab)
if (tab.length > 0) {
data = tab[0].url;
let qrInfo = `<img id="qr" src = "http://qr.topscan.com/api.php?text=" + ${data}>`
sendMessageToContentScript("generateQr", qrInfo);
}
});
}
});

chrome.contextMenus.create({
id: "3",
title: `${chrome.i18n.getMessage("tabsMenu")}`,
contexts: ["browser_action"]
});

chrome.contextMenus.create({
id: "4",
title: `${chrome.i18n.getMessage("showAllTabs")}`,
contexts: ["browser_action"],
onclick: function () {
openBackgroundPage();
},
parentId: "3"
});

chrome.contextMenus.create({
id: "5",
title: `${chrome.i18n.getMessage("sendAllTabs")}`,
contexts: ["browser_action"],
onclick: function () {
chrome.tabs.query({ url: ["https://*/*", "http://*/*"], currentWindow: true }, function (req) {
if (req.length > 0) {
saveTabs(req);
openBackgroundPage();
closeTabs(req);
} else {
openBackgroundPage();
}
});
},
parentId: "3"
});


chrome.contextMenus.create({
id: "6",
title: `${chrome.i18n.getMessage("sendCurrentTab")}`,
contexts: ["browser_action"],
onclick: function () {
chrome.storage.local.get(function (storage) {
let opts = storage.options
let openBackgroundAfterSendTab = "yes"
if (opts) {
openBackgroundAfterSendTab = opts.openBackgroundAfterSendTab || "yes"
}
chrome.tabs.query({ url: ["https://*/*", "http://*/*"], highlighted: true, currentWindow: true }, function (req) {
if (req.length > 0) {
saveTabs(req);
if (openBackgroundAfterSendTab === "yes") {
openBackgroundPage();
}
closeTabs(req);
} else {
if (openBackgroundAfterSendTab === "yes") {
openBackgroundPage();
}
}
});
})
},
parentId: "3"
});


chrome.contextMenus.create({
id: "7",
title: `${chrome.i18n.getMessage("sendOtherTabs")}`,
contexts: ["browser_action"],
onclick: function () {
chrome.tabs.query({ url: ["https://*/*", "http://*/*"], active: false, currentWindow: true }, function (req) {
if (req.length > 0) {
saveTabs(req);
openBackgroundPage();
closeTabs(req);
} else {
openBackgroundPage();
}
});
},
parentId: "3"
});


chrome.contextMenus.create({
id: "8",
title: `${chrome.i18n.getMessage("remindMenu")}`,
contexts: ["browser_action"]
});

chrome.contextMenus.create({
id: "9",
title: `${chrome.i18n.getMessage("fiveMinuteRemind")}`,
contexts: ["browser_action"],
onclick: function () {
remind(5);
},
parentId: "8"
});


chrome.contextMenus.create({
id: "10",
title: `${chrome.i18n.getMessage("tenMinuteRemind")}`,
contexts: ["browser_action"],
onclick: function () {
remind(10);
},
parentId: "8"
});


chrome.contextMenus.create({
id: "11",
title: `${chrome.i18n.getMessage("fortyMinuteRemind")}`,
contexts: ["browser_action"],
onclick: function () {
remind(40);
},
parentId: "8"
});


chrome.contextMenus.create({
id: "12",
title: `${chrome.i18n.getMessage("customMinuteRemind")}`,
contexts: ["browser_action"],
onclick: function () {
var minute = prompt(`${chrome.i18n.getMessage("pleaseInputCustomMinute")}`, 120);
if (!isInt(parseInt(minute.trim()))) {
alert(`${chrome.i18n.getMessage("inputNumber")}`)
} else {
remind(Number(minute.trim()));
}
},
parentId: "8"
});


chrome.contextMenus.create({
id: "13",
title: `${chrome.i18n.getMessage("openJsonTools")}`,
contexts: ["browser_action"],
onclick: function () {
chrome.tabs.create({ index: 0, url: chrome.extension.getURL('json.html') });
}
});
8 changes: 8 additions & 0 deletions js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ chrome.runtime.onMessage.addListener(function (req, sender, sendRes) {
sendRes('ok'); // acknowledge
tip(req.message);
break;
case 'generateQr':
sendRes('ok'); // acknowledge
var screenWidth = document.body.clientWidth + document.body.scrollLeft;
pageX = screenWidth / 2
pageY = 70
scrollTop = 0
tip(req.message);
break;
default:
sendRes('nope'); // acknowledge
break;
Expand Down
Loading

0 comments on commit 3370620

Please sign in to comment.