mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-10-07 16:35:15 +08:00
合并网页截图功能(张君秋的代码)
This commit is contained in:
@@ -1,30 +1,34 @@
|
||||
chrome.contextMenus.create({
|
||||
id: 'bitdance',
|
||||
title: '学生助手'
|
||||
id: 'bitdance',
|
||||
title: '学生助手'
|
||||
})
|
||||
|
||||
// chrome.contextMenus.onClicked.addListener(function (info) {
|
||||
// alert('当前菜单信息:'+ JSON.stringify(info))
|
||||
// })
|
||||
|
||||
// 打印消息日志
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
console.log("request", request, "path", sender.url.replace(sender.origin, ""), "sender", sender, "sendResponse", sendResponse);
|
||||
})
|
||||
|
||||
|
||||
//refer: https://github.com/GoogleChrome/chrome-extensions-samples/blob/main/mv2-archive/api/notifications/background.js
|
||||
function showNotification() {
|
||||
var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time.
|
||||
var hour = time[1] % 12 || 12; // The prettyprinted hour.
|
||||
var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day.
|
||||
new Notification(hour + time[2] + ' ' + period, {
|
||||
icon: '48.png',
|
||||
body: 'Time to make the toast.'
|
||||
});
|
||||
var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time.
|
||||
var hour = time[1] % 12 || 12; // The prettyprinted hour.
|
||||
var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day.
|
||||
new Notification(hour + time[2] + ' ' + period, {
|
||||
icon: '48.png',
|
||||
body: 'Time to make the toast.'
|
||||
});
|
||||
}
|
||||
|
||||
chrome.contextMenus.create({
|
||||
id: 'bitdance-advanced-search-notification',
|
||||
title: 'Notification',
|
||||
parentId: 'bitdance',
|
||||
onclick: function (info) {
|
||||
showNotification()
|
||||
}
|
||||
})
|
||||
id: 'bitdance-advanced-search-notification',
|
||||
title: 'Notification',
|
||||
parentId: 'bitdance',
|
||||
onclick: function (info) {
|
||||
showNotification()
|
||||
}
|
||||
})
|
||||
|
@@ -1 +1 @@
|
||||
console.log("[BitDance extension] 学生助手插件已启用")
|
||||
console.log("[BitDance extension] 学生助手插件已启用")
|
||||
|
@@ -7,9 +7,10 @@ $(function() {
|
||||
|
||||
// 每次改变开关状态时刷新页面使功能及时生效
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
console.log('click');
|
||||
location.reload();
|
||||
sendResponse('Reload page');
|
||||
// TODO: 这里不能这么写,否则会导致其他模块发送消息时触发页面刷新
|
||||
// console.log('click');
|
||||
// location.reload();
|
||||
// sendResponse('Reload page');
|
||||
})
|
||||
|
||||
// 控制功能是否开启
|
||||
@@ -92,4 +93,4 @@ $(function() {
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
|
@@ -6,9 +6,10 @@ $(function() {
|
||||
console.log("[BitDance extension] 学生助手插件 - 鼠标样式模块加载成功");
|
||||
// 每次改变开关状态时刷新页面使功能及时生效
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
console.log('mouse');
|
||||
location.reload();
|
||||
sendResponse('Reload page');
|
||||
// TODO: 这里不能这么写,否则会导致其他模块发送消息时触发页面刷新
|
||||
// console.log('mouse');
|
||||
// location.reload();
|
||||
// sendResponse('Reload page');
|
||||
})
|
||||
|
||||
// 控制功能是否开启
|
||||
@@ -24,4 +25,4 @@ $(function() {
|
||||
});
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -71,4 +71,11 @@ $(function() {
|
||||
btnDirectUrl.addEventListener("change", () => {
|
||||
chrome.storage.sync.set({ linkOpen: !btnDirectUrl.checked });
|
||||
});
|
||||
|
||||
// 截图
|
||||
document.getElementById("btnScreenshot").addEventListener("click", () => {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||
chrome.extension.getBackgroundPage().takeScreenshot(tabs[0]);
|
||||
})
|
||||
});
|
||||
})
|
||||
|
Reference in New Issue
Block a user