1
0
mirror of https://gitee.com/bitdance-team/chrome-extension synced 2025-03-13 09:23:34 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

Merge branch 'develop' of gitee.com:bitdance-team/chrome-extension into feat-sst

This commit is contained in:
kaz 2022-02-09 11:48:50 +08:00
commit 250d8bdb22
52 changed files with 14924 additions and 32 deletions

View File

@ -0,0 +1,161 @@
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
body {
background: linear-gradient(to right bottom, #fbc2eb 0%, #a6c1ee 51%, #fbc2eb 100%);
}
#popup {
min-height: 450px;
width: 300px;
}
#popup header {
width: inherit;
height: 30px;
background: linear-gradient(to right, #f6d365 0%, #fda085 51%, #f6d365 100%);
}
#popup header img {
height: inherit;
}
#popup .article ul li {
margin: 5px 0;
height: 45px;
background: linear-gradient(to right, #84fab0 0%, #8fd3f4 51%, #84fab0 100%);
}
#popup .article ul li span {
font-size: 16px;
line-height: 45px;
margin-left: 5px;
}
#popup .article ul li #click-per .button {
position: relative;
float: right;
top: 6px;
right: 6px;
width: 66px;
height: 32px;
border-radius: 100px;
}
#popup .article ul li #click-per .button .checkbox {
position: relative;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
z-index: 3;
}
#popup .article ul li #click-per .button .knobs,
#popup .article ul li #click-per .button .layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#popup .article ul li #click-per .button .knobs {
z-index: 2;
}
#popup .article ul li #click-per .button .layer {
border-radius: 100px;
width: 100%;
background-color: #ebf7fc;
z-index: 1;
}
#popup .article ul li #click-per .button .knobs::before {
content: "YES";
position: absolute;
top: 2px;
left: 34px;
width: 20px;
height: 10px;
color: #fff;
font-size: 10px;
font-weight: bold;
text-align: center;
line-height: 1;
padding: 9px 4px;
background-color: #03a9f4;
border-radius: 50%;
}
#popup .article ul li #click-per .button .checkbox:checked + .knobs:before {
content: "NO";
left: 3px;
background-color: #f44336;
}
#popup .article ul li #click-per .button .checkbox:checked ~ .layer {
background-color: #fcebeb;
}
#popup .article ul li #click-per .button .knobs,
#popup .article ul li #click-per .button .knobs:before,
#popup .article ul li #click-per .button .layer {
transition: 0.3s ease all;
}
#popup .article ul li #mouse-style .button {
position: relative;
float: right;
top: 6px;
right: 6px;
width: 66px;
height: 32px;
border-radius: 100px;
}
#popup .article ul li #mouse-style .button .checkbox {
position: relative;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
z-index: 3;
}
#popup .article ul li #mouse-style .button .knobs,
#popup .article ul li #mouse-style .button .layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#popup .article ul li #mouse-style .button .knobs {
z-index: 2;
}
#popup .article ul li #mouse-style .button .layer {
border-radius: 100px;
width: 100%;
background-color: #ebf7fc;
z-index: 1;
}
#popup .article ul li #mouse-style .button .knobs::before {
content: "YES";
position: absolute;
top: 2px;
left: 34px;
width: 20px;
height: 10px;
color: #fff;
font-size: 10px;
font-weight: bold;
text-align: center;
line-height: 1;
padding: 9px 4px;
background-color: #03a9f4;
border-radius: 50%;
}
#popup .article ul li #mouse-style .button .checkbox:checked + .knobs:before {
content: "NO";
left: 3px;
background-color: #f44336;
}
#popup .article ul li #mouse-style .button .checkbox:checked ~ .layer {
background-color: #fcebeb;
}
#popup .article ul li #mouse-style .button .knobs,
#popup .article ul li #mouse-style .button .knobs:before,
#popup .article ul li #mouse-style .button .layer {
transition: 0.3s ease all;
}

View File

@ -0,0 +1,172 @@
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
body {
background: linear-gradient(to right bottom, #fbc2eb 0%, #a6c1ee 51%, #fbc2eb 100%);
}
#popup {
min-height: 450px;
width: 300px;
header{
width: inherit;
height: 30px;
background: linear-gradient(to right, #f6d365 0%, #fda085 51%, #f6d365 100%);;
img {
height: inherit;
}
}
.article{
ul{
li{
margin: 5px 0;
height: 45px;
background: linear-gradient(to right, #84fab0 0%, #8fd3f4 51%, #84fab0 100%);
span{
font-size: 16px;
line-height: 45px;
margin-left: 5px;
}
#click-per{
.button {
position: relative;
float: right;
top: 6px;
right: 6px;
width: 66px;
height: 32px;
border-radius: 100px;
.checkbox {
position: relative;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
z-index: 3;
}
.knobs,
.layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.knobs {
z-index: 2;
}
.layer{
border-radius: 100px;
width: 100%;
background-color: #ebf7fc;
z-index: 1;
}
.knobs::before {
content: "YES";
position: absolute;
top: 2px;
left: 34px;
width: 20px;
height: 10px;
color: #fff;
font-size: 10px;
font-weight: bold;
text-align: center;
line-height: 1;
padding: 9px 4px;
background-color: #03a9f4;
border-radius: 50%;
}
.checkbox:checked+.knobs:before {
content: "NO";
left: 3px;
background-color: #f44336;
}
.checkbox:checked~.layer {
background-color: #fcebeb;
}
.knobs,
.knobs:before,
.layer{
transition: 0.3s ease all;
}
}
}
#mouse-style{
.button {
position: relative;
float: right;
top: 6px;
right: 6px;
width: 66px;
height: 32px;
border-radius: 100px;
.checkbox {
position: relative;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
z-index: 3;
}
.knobs,
.layer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.knobs {
z-index: 2;
}
.layer{
border-radius: 100px;
width: 100%;
background-color: #ebf7fc;
z-index: 1;
}
.knobs::before {
content: "YES";
position: absolute;
top: 2px;
left: 34px;
width: 20px;
height: 10px;
color: #fff;
font-size: 10px;
font-weight: bold;
text-align: center;
line-height: 1;
padding: 9px 4px;
background-color: #03a9f4;
border-radius: 50%;
}
.checkbox:checked+.knobs:before {
content: "NO";
left: 3px;
background-color: #f44336;
}
.checkbox:checked~.layer {
background-color: #fcebeb;
}
.knobs,
.knobs:before,
.layer{
transition: 0.3s ease all;
}
}
}
}
}
}
}

View File

@ -0,0 +1,176 @@
@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap');
body {
/* background-color: rgb(51, 11, 116); */
background: url(../../images/pomo_green.jpeg) no-repeat;
background-image: "../../";
/* color: white; */
font-family: 'Source Sans Pro','Fira Sans', sans-serif;
margin: 0;
padding: 0;
/* width: 280px; */
/* height: 500px; */
height: 200px;
}
#timer {
/* background-color: rgb(77, 25, 161); */
padding: 10px 0 20px;
}
.buttons {
width: fit-content;
margin: auto;
font-size: 20px;
color: rgb(169, 172, 172);
}
.buttons .slider{
color: rgb(247, 226, 230);
}
.button {
float: left;
margin: 5px;
cursor: pointer;
padding: 8px;
}
/*计数部分*/
#countdown {
clear: both;
width: fit-content;
margin: auto;
font-size: 60px;
font-weight: 500;
padding: 20%;
color: aliceblue;
}
#countdown span{
opacity: 0;
}
#start-btn,#end-btn,#reset-btn {
/* 文字颜色 */
color: #f5e4b9;
/* 清除背景色 */
background: transparent;
/* 边框样式、颜色、宽度 */
border: 1px solid #f5e4b9;
/* 给边框添加圆角 */
border-radius: 6px;
/* 字母转大写 */
border: none;
color: white;
padding: 10px 26px;
display: block;
text-align: center;
/* width: 40px; */
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
cursor: pointer;
text-decoration: none;
text-transform: uppercase;
text-shadow: 1px 1px 1px rgba(255,255,255, .1);
border-radius: 25px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
#start-btn {
background-color: white;
color: black;
border: 1px solid #f5e4b9;
}
/* 悬停样式 */
#start-btn:hover {
background-color: #f5e4b9;
color: white;
}
#end-btn {
background-color: white;
color: black;
border: 1px solid #ECB390;
display: none;
}
/* 悬停样式 */
#end-btn:hover {
background-color: #ECB390;
color: white;
}
/* #end-btn{
width: 40px;
margin: 10px auto 0;
padding: 10px 30px;
text-align: center;
background-color: #F5EEDC;
cursor: pointer;
} */
/* #reset-btn {
width: 40px;
margin: 10px auto 0;
padding: 10px 30px;
text-align: center;
background-color: #DD4A48;
cursor: pointer;
} */
#reset-btn {
background-color: white;
color: black;
border: 1px solid #DD4A48;
}
/* 悬停样式 */
#reset-btn:hover {
background-color: #DD4A48;
color: white;
}
/* #end-btn{
background-color: #ECB390;
display: none;
} */
/*选中的按钮*/
.selected {
background-color: rgb(244, 242, 248);
}
ul {
padding: 0;
}
li {
list-style-type: none;
padding: 20px 10px;
margin-bottom: 5px;
background-color: white;
color: black;
}
.right {
float: right;
}
.hide {
display: none;
}
footer .settings{
position: absolute;
bottom: 5px;
right: 5px;
}

View File

@ -0,0 +1,222 @@
// const btn = document.querySelector("#switch");
// chrome.storage.sync.get("linkOpen", ({ linkOpen }) => {
// btn.checked = linkOpen;
// });
// btn.addEventListener("change", () => {
// if (btn.checked) {
// chrome.storage.sync.set({ linkOpen: true });
// } else {
// chrome.storage.sync.set({ linkOpen: false });
// }
// // 获取当前tab窗口
// chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
// chrome.scripting.executeScript({
// target: { tabId: tabs[0].id },
// func: refreshPage,
// });
// });
// });
// // 刷新页面
// function refreshPage() {
// window.location.reload();
// }
const startBtn = document.getElementById("start-btn");
const resetBtn = document.getElementById("reset-btn");
const endBtn = document.getElementById("end-btn");
const countdownTimer = document.getElementById("countdown");
const audio = document.getElementById("audio");
//全局唯一的定时器
let timer = null;
let minutes, seconds;
let pause;
let pomodoro = "pomodoro";
//两端通信 防抖
// let clickFlag = false;
//番茄钟按钮-绑定事件
document.addEventListener("click", (e) => {
if (!e.target.matches(".button")) return;
// reset when pomodoro button selected
pause = true;
seconds = 60;
startBtn.innerHTML = "开始";
chrome.storage.sync.set({ pause: pause, seconds: seconds }, function () {
if (!chrome.runtime.error) {
alert("初始化pause、seconds");
}
});
// 定时器初始化
if (e.target.matches("#pomodoro-btn")) {
countdownTimer.innerHTML = "25:00";
pomodoro = "pomodoro";
minutes = 25;
chrome.storage.sync.set(
{ minutes: minutes, countdownTimer: "25:00" },
function () {
if (!chrome.runtime.error) {
alert("added target pomodoro!");
}
}
);
}
});
// 开始按钮-绑定事件
startBtn.addEventListener("click", () => {
// countdown(); 在后台运行,需要取出状态
debounce(start(), 100);
});
function start() {
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
const { minutes, seconds, status } = pomoData;
chrome.runtime.sendMessage(
{
status: "start",
senderId: "pomo",
content: {
minutes,
seconds,
},
},
(response) => {
console.log(response);
startBtn.style.display = "none";
endBtn.style.display = "block";
getTimer();
}
);
});
}
endBtn.addEventListener("click", () => {
setTimeout(end, 200);
});
function end() {
chrome.runtime.sendMessage(
{
status: "paused",
senderId: "pomo",
},
(response) => {
console.log(response);
startBtn.style.display = "block";
endBtn.style.display = "none";
clearTimer();
}
);
}
function getTimer() {
clearTimer();
timer = setInterval(() => {
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
// console.log("pomodata****",pomoData)
// const{minutes,seconds,countdownTimer} = pomoData;
countdownTimer.innerHTML = pomoData.countdownTimer;
//更新后倒计时判断,如果结束则重新初始化界面
if(pomoData.countdownTimer == "00:00"){
audio.play();
//不能放在页面上,要在后台进行
chrome.runtime.sendMessage(
{
status: "playend",
senderId: "pomo",
},
(response) => {
console.log(response,"**************下面");
countdownTimer.innerHTML = "25:00";
startBtn.style.display = "block";
endBtn.style.display = "none";
clearTimer();
}
);
}
});
}, 200);
}
function clearTimer() {
clearInterval(timer);
}
/*
* fn [function] 需要防抖的函数
* delay [number] 毫秒防抖期限值
*/
function debounce(fn, delay) {
let timer = null; //借助闭包
return function () {
if (timer) {
clearTimeout(timer); //进入该分支语句,说明当前正在一个计时过程中,并且又触发了相同事件。所以要取消当前的计时,重新开始计时
timer = setTimeout(fn, delay);
} else {
timer = setTimeout(fn, delay); // 进入该分支说明当前并没有在计时,那么就开始一个计时
}
};
}
// 重置按钮-绑定事件
resetBtn.addEventListener("click", () => {
setTimeout(() => {
chrome.runtime.sendMessage(
{
status: "reset",
senderId: "pomo",
},
(response) => {
// console.log(response);
countdownTimer.innerHTML = "25:00";
startBtn.style.display = "block";
endBtn.style.display = "none";
clearTimer();
}
);
}, 100);
});
//页面反复打开时页面初始化
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
console.log(pomoData);
const { status } = pomoData;
if (status === "start") {
startBtn.style.display = "none";
endBtn.style.display = "block";
getTimer();
} else if (status === "paused") {
startBtn.style.display = "block";
endBtn.style.display = "none";
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
countdownTimer.innerHTML = pomoData.countdownTimer;
});
} else if (status === "init") {
chrome.runtime.sendMessage({
status: "init",
senderId: "pomo",
});
countdownTimer.innerHTML = "25:00";
}else if(status === 'playend'){
countdownTimer.innerHTML = "25:00";
}
});

View File

@ -0,0 +1,156 @@
// 用户首次安装插件时执行一次,后面不会再重新执行(除非用户重新安装插件)
chrome.runtime.onInstalled.addListener(() => {
// 插件功能安装默认启用
chrome.storage.sync.set({
//初始化数据
pomoData: {
minutes: 24,
seconds: 60,
countdownTimer: "25:00",
status: "init",
},
});
});
let minutes, seconds;
let pause;
let pomodoro = "pomodoro";
let array = ["minutes", "seconds", "pause", "countdownTimer", "pbutton"];
//全局唯一的定时器
let timer = null;
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log(`进入 assets\html\pomodoro\background.js 中的onMessage Listener`)
if (message.senderId !== "pomo") {
// 抛给下一个Listener
sendResponse();
}
const { status, content } = message;
if (status === "start") {
// sendResponse({
// status:message.status
// })
countdown({ ...content, status });
} else if (status === "paused") {
clearTimeout(timer);
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
console.log(pomoData);
chrome.storage.sync.set({ pomoData: { ...pomoData, status: "paused" } });
});
} else if (status === "reset") {
clearTimeout(timer);
chrome.storage.sync.set({
pomoData: {
minutes: 24,
seconds: 60,
countdownTimer: "25:00",
status: "init",
},
});
chrome.browserAction.setBadgeText({ text: "" });
} else if (status === "init") {
//init初始化
chrome.storage.sync.set({
pomoData: {
minutes: 24,
seconds: 60,
countdownTimer: "25:00",
status: "start",
},
});
} else {
//playend 初始化
chrome.storage.sync.set({
pomoData: {
minutes: 24,
seconds: 60,
countdownTimer: "25:00",
status: "playend",
},
});
}
//创建结束通知:待完成
chrome.storage.sync.set({
status,
});
//后台播放完成提示音乐
if (message.action === "play") {
// audio.play();
}
sendResponse();
console.log(`离开 assets\html\pomodoro\background.js 中的onMessage Listener`)
return true;
});
// 番茄钟倒计时功能
function countdown({ minutes, seconds, status }) {
// 设置分钟和秒数
// let currentMins = minutes - 1;
seconds--;
let currentTimer =
(minutes < 10 ? "0" : "") +
minutes +
":" +
(seconds < 10 ? "0" : "") +
seconds;
// countdownTimer.innerHTML = currentTimer; 拿到
console.log("分秒=============", minutes, seconds);
chrome.storage.sync.set(
{
pomoData: {
seconds: seconds,
minutes: minutes,
countdownTimer: currentTimer,
status,
},
},
function () {
if (!chrome.runtime.error) {
console.log("started");
}
}
);
//设置badge文本用来显示剩余分钟数
chrome.storage.sync.get("pomoData", ({ pomoData }) => {
chrome.browserAction.setBadgeText({ text: pomoData.minutes.toString() + ":" + pomoData.seconds.toString() });
});
console.log(currentTimer);
// count down every second, when a minute is up, countdown one minute
// when time reaches 0:00, reset
if (seconds > 0) {
timer = setTimeout(() => {
countdown({ minutes, seconds, status });
}, 1000);
} else if (minutes > 0) {
seconds = 60;
minutes--;
chrome.storage.sync.set(
{
pomoData: {
seconds: seconds,
minutes: minutes,
countdownTimer: currentTimer,
status,
},
},
function () {
if (!chrome.runtime.error) {
console.log("started");
}
}
);
countdown({ minutes, seconds, status });
}
}
//设置badge文本背景颜色
chrome.browserAction.setBadgeBackgroundColor({ color: "#DD4A48" });

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

@ -0,0 +1,9 @@
<html>
<body>
<p>播放歌曲时的一些不错的文字。</p> <音频自动播放>
<source
src =http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3type=audio/mpeg /> <source src
=http://www.html5rocks.com/en/tutorials/audio/quick/test.oggtype=audio/ogg />
</audio>
</body>
</html>

View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>my todo list</title>
<link rel="stylesheet" href="./assets/css/popup.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400&display=swap" rel="stylesheet">
</head>
<body>
<audio id="audio">
<source src="./src/alarm.mp3" type="audio/mp3">
</audio>
<!-- 计时部分 -->
<div id="timer">
<!-- 切换背景图片 -->
<div class="slider">
<span class="left">&lt;</span>
<span class="right">&gt;</span>
</div>
<!-- <div class="button" id="pomodoro-btn"></div> -->
<div id="countdown">
<span>00:00</span>
</div>
<div class="buttons">
<!-- 计时开始、重置 -->
<button id="start-btn">开始</button>
<button id="end-btn">暂停</button>
<button id="reset-btn">重置</button>
</div>
</div>
<!-- 后续——添加任务清单
<div id="worklist">
<div id="current-task-display">
<div id="message">你正在专注于:</div>
<div id="selected-task"></div>
</div>
<div id="tasks-container">
<ul id="tasks"></ul>
<div id="add-task-btn">Add Task</div>
<form id="task-form" class="hide">
<input id="text" type="text" placeholder="输入你要专注的事情">
<div id="btn-container">
<button id="save" type="submit">Save</button>
<button id="cancel" type="button">Cancel</button>
</div>
</form>
</div>
</div> -->
<!-- 页脚--设置 -->
<footer>
<div class="settings">
<!-- <a href="./assets/html/options.html">settings</a> -->
</div>
</footer>
<script src="./assets/js/popup.js"></script>
</body>
</html>

View File

@ -0,0 +1,108 @@
// 设置截图方法和存储方法。
chrome.storage.sync.get((config) => {
chrome.storage.sync.set({ method: 'crop' });
chrome.storage.sync.set({ format: 'png' });
chrome.storage.sync.set({ save: 'file' });
chrome.storage.sync.set({ dpr: true });
if (config.save === 'clipboard') {
config.save = 'url'
chrome.storage.sync.set({ save: 'url' })
}
})
// 定义inject函数点击图标就执行
function inject(tab) {
chrome.tabs.sendMessage(tab.id, { message: 'init' }, (res) => {
if (res) {
// 停止植入css和js文件。
clearTimeout(timeout)
}
})
// 植入css和js文件
var timeout = setTimeout(() => {
var relativePath = 'assets/html/screenshot/'
chrome.tabs.insertCSS(tab.id, { file: relativePath + 'css/jquery.Jcrop.min.css', runAt: 'document_start' })
chrome.tabs.insertCSS(tab.id, { file: relativePath + 'css/content.css', runAt: 'document_start' })
chrome.tabs.executeScript(tab.id, { file: relativePath + 'js/jquery.min.js', runAt: 'document_start' })
chrome.tabs.executeScript(tab.id, { file: relativePath + 'js/jquery.Jcrop.min.js', runAt: 'document_start' })
chrome.tabs.executeScript(tab.id, { file: relativePath + 'js/content.js', runAt: 'document_start' })
// 间隔发送"init"message
setTimeout(() => {
chrome.tabs.sendMessage(tab.id, { message: 'init' })
}, 100)
}, 100)
}
var takeScreenshot = inject
chrome.runtime.onMessage.addListener((req, sender, res) => {
console.log(`进入 assets\html\screenshot\background.js 中的onMessage Listener`)
if (req.senderId !== "screenshot") {
// 抛给下一个Listener
res();
}
if (req.message === 'capture') {
console.log("capture开始")
chrome.storage.sync.get((config) => {
chrome.tabs.getSelected(null, (tab) => {
chrome.tabs.captureVisibleTab(tab.windowId, { format: config.format }, (image) => {
// 整个网页截图
// console.log("image", image);
crop(image, req.area, req.dpr, config.dpr, config.format, (cropped) => {
// 裁剪后
// console.log("cropped", cropped)
console.log("capture结束")
res({ message: 'image', image: cropped })
// 回调有问题,参数么有传回去,使用以下变通方式直接转换为可下载的文件
var link = document.createElement('a'); link.download = "学生助手截图-" + Date.now(); link.href = cropped; link.click();
})
})
})
})
}
else if (req.message === 'active') {
if (req.active) {
chrome.browserAction.setTitle({ tabId: sender.tab.id, title: 'Crop and Save' })
// chrome.browserAction.setBadgeText({tabId: sender.tab.id, text: '◩'})
}
else {
chrome.browserAction.setTitle({ tabId: sender.tab.id, title: 'Screenshot Capture' })
// chrome.browserAction.setBadgeText({tabId: sender.tab.id, text: ''})
}
}
console.log(`离开 assets\html\screenshot\background.js 中的onMessage Listener`)
return true
})
function crop(image, area, dpr, preserve, format, done) {
var top = area.y * dpr
var left = area.x * dpr
var width = area.w * dpr
var height = area.h * dpr
var w = (dpr !== 1 && preserve) ? width : area.w
var h = (dpr !== 1 && preserve) ? height : area.h
var canvas = null
if (!canvas) {
canvas = document.createElement('canvas')
document.body.appendChild(canvas)
}
canvas.width = w
canvas.height = h
var img = new Image()
img.onload = () => {
var context = canvas.getContext('2d')
context.drawImage(img,
left, top,
width, height,
0, 0,
w, h
)
var cropped = canvas.toDataURL(`image/${format}`)
done(cropped)
}
img.src = image
}

View File

@ -0,0 +1,18 @@
img#fake-image,
.jcrop-holder,
.jcrop-holder img,
.jcrop-tracker {
width: 100% !important; height: 100% !important;
max-width: 100% !important; max-height: 100% !important;
min-width: 100% !important; min-height: 100% !important;
}
img#fake-image {
position: fixed; top: 0; left: 0; z-index: 1;
}
.jcrop-holder {
position: fixed !important; top: 0 !important; left: 0 !important;
z-index: 2147483647 !important;
}

View File

@ -0,0 +1,146 @@
/* jquery.Jcrop.min.css v0.9.12 (build:20140524) */
.jcrop-holder {
direction: ltr;
text-align: left;
-ms-touch-action: none;
}
.jcrop-hline,
.jcrop-vline {
background-color: #fff;
font-size: 0;
position: absolute;
}
.jcrop-vline {
height: 100%;
width: 1px !important;
}
.jcrop-vline.right {
right: 0;
}
.jcrop-hline {
height: 1px !important;
width: 100%;
}
.jcrop-hline.bottom {
bottom: 0;
}
.jcrop-tracker {
height: 100%;
width: 100%;
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
-webkit-user-select: none;
}
.jcrop-handle {
background-color: #333;
border: 1px #eee solid;
width: 7px;
height: 7px;
font-size: 1px;
}
.jcrop-handle.ord-n {
left: 50%;
margin-left: -4px;
margin-top: -4px;
top: 0;
}
.jcrop-handle.ord-s {
bottom: 0;
left: 50%;
margin-bottom: -4px;
margin-left: -4px;
}
.jcrop-handle.ord-e {
margin-right: -4px;
margin-top: -4px;
right: 0;
top: 50%;
}
.jcrop-handle.ord-w {
left: 0;
margin-left: -4px;
margin-top: -4px;
top: 50%;
}
.jcrop-handle.ord-nw {
left: 0;
margin-left: -4px;
margin-top: -4px;
top: 0;
}
.jcrop-handle.ord-ne {
margin-right: -4px;
margin-top: -4px;
right: 0;
top: 0;
}
.jcrop-handle.ord-se {
bottom: 0;
margin-bottom: -4px;
margin-right: -4px;
right: 0;
}
.jcrop-handle.ord-sw {
bottom: 0;
left: 0;
margin-bottom: -4px;
margin-left: -4px;
}
.jcrop-dragbar.ord-n,
.jcrop-dragbar.ord-s {
height: 7px;
width: 100%;
}
.jcrop-dragbar.ord-e,
.jcrop-dragbar.ord-w {
height: 100%;
width: 7px;
}
.jcrop-dragbar.ord-n {
margin-top: -4px;
}
.jcrop-dragbar.ord-s {
bottom: 0;
margin-bottom: -4px;
}
.jcrop-dragbar.ord-e {
margin-right: -4px;
right: 0;
}
.jcrop-dragbar.ord-w {
margin-left: -4px;
}
.jcrop-light .jcrop-hline,
.jcrop-light .jcrop-vline {
background: #fff;
filter: alpha(opacity=70) !important;
opacity: 0.7 !important;
}
.jcrop-light .jcrop-handle {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
background-color: #000;
border-color: #fff;
border-radius: 3px;
}
.jcrop-dark .jcrop-hline,
.jcrop-dark .jcrop-vline {
background: #000;
filter: alpha(opacity=70) !important;
opacity: 0.7 !important;
}
.jcrop-dark .jcrop-handle {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
background-color: #fff;
border-color: #000;
border-radius: 3px;
}
.solid-line .jcrop-hline,
.solid-line .jcrop-vline {
background: #fff;
}
.jcrop-holder img,
img.jcrop-preview {
max-width: none;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

View File

@ -0,0 +1,132 @@
var jcrop, selection
var relativePath = 'assets/html/screenshot'
var overlay = ((active) => (state) => {
active = typeof state === 'boolean' ? state : state === null ? active : !active
$('.jcrop-holder')[active ? 'show' : 'hide']()
chrome.runtime.sendMessage({ message: 'active', senderId: "screenshot", active })
})(false)
var image = (done) => {
var image = new Image()
image.id = 'fake-image'
image.src = chrome.runtime.getURL(relativePath + '/images/pixel.png')
image.onload = () => {
$('body').append(image)
done()
}
}
var init = (done) => {
$('#fake-image').Jcrop({
bgColor: 'none',
onSelect: (e) => {
selection = e
capture()
},
onChange: (e) => {
selection = e
},
onRelease: (e) => {
setTimeout(() => {
selection = null
}, 100)
}
}, function ready() {
jcrop = this
$('.jcrop-hline, .jcrop-vline').css({
backgroundImage: `url(${chrome.runtime.getURL(relativePath + '/images/Jcrop.gif')})`
})
if (selection) {
jcrop.setSelect([
selection.x, selection.y,
selection.x2, selection.y2
])
}
done && done()
})
}
var capture = (force) => {
chrome.storage.sync.get((config) => {
console.log(config)
if (selection && (config.method === 'crop' || (config.method === 'wait' && force))) {
jcrop.release()
setTimeout(() => {
console.log("准备capture")
chrome.runtime.sendMessage({
message: 'capture', senderId: "screenshot", area: selection, dpr: devicePixelRatio
}, (res) => {
console.log("capture回调结果", res)
return // 变通
overlay(false)
selection = null
save(res.image, config.format, config.save)
})
}, 50)
}
else if (config.method === 'view') {
chrome.runtime.sendMessage({
message: 'capture', senderId: "screenshot",
area: { x: 0, y: 0, w: innerWidth, h: innerHeight }, dpr: devicePixelRatio
}, (res) => {
overlay(false)
save(res.image, config.format, config.save)
})
}
})
}
var filename = (format) => {
var pad = (n) => (n = n + '', n.length >= 2 ? n : `0${n}`)
var ext = (format) => format === 'jpeg' ? 'jpg' : format === 'png' ? 'png' : 'png'
var timestamp = (now) =>
[pad(now.getFullYear()), pad(now.getMonth() + 1), pad(now.getDate())].join('-')
+ ' - ' +
[pad(now.getHours()), pad(now.getMinutes()), pad(now.getSeconds())].join('-')
return `Screenshot Capture - ${timestamp(new Date())}.${ext(format)}`
}
var save = (image, format, save) => {
var link = document.createElement('a')
link.download = filename(format)
link.href = image
link.click()
}
window.addEventListener('resize', ((timeout) => () => {
clearTimeout(timeout)
timeout = setTimeout(() => {
jcrop.destroy()
init(() => overlay(null))
}, 100)
})())
chrome.runtime.onMessage.addListener((req, sender, res) => {
console.log(`进入 assets\html\screenshot\js\content.js 中的onMessage Listener`)
if (req.senderId !== "screenshot") {
// 抛给下一个Listener
res();
}
if (req.message === 'init') {
res({}) // prevent re-injecting
if (!jcrop) {
image(() => init(() => {
overlay()
capture()
}))
}
else {
overlay()
capture(true)
}
}
console.log(`离开 assets\html\screenshot\js\content.js 中的onMessage Listener`)
return true
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,36 @@
{
"manifest_version": 2,
"name" : "Screenshot Capture",
"version" : "2.0",
"description" : "Screenshot Capture",
"browser_action": {
"default_title": "Screenshot Capture"
},
"background" : {
"scripts": [
"background.js"
],
"persistent": false
},
"web_accessible_resources": [
"/images/Jcrop.gif",
"/images/pixel.png"
],
"commands": {
"take-screenshot": {
"suggested_key": {
"default": "Alt+S"
},
"description": "Take Screenshot"
}
},
"permissions": [
"storage",
"activeTab"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,864 @@
// 注册右键菜单
chrome.contextMenus.create({
id: 'bitdance-advanced-search',
title: '高级搜索',
parentId: 'bitdance',
onclick: function (info) {
alert('当前菜单信息:' + JSON.stringify(info))
alert("[BitDance extension] 学生助手插件 - 高级搜索 已点击菜单")
}
})
/**
* ss 的寓意
*
* - 搜索 (sou suo)
*
* - 超级搜索 (super search)
* - 智慧搜索 (smart search)
* - 洞见搜索 (sagacious search)
* - 流畅搜索 (smooth search)
* - 安全搜索 (safe search)
*
* 当然还有...
* - 简单搜索 (simple search)
* - 愚蠢搜索 (stupid search)
*
* 即使有上面那么多的功能但我们不往初心
*
* - 开创探索 (seminal search)
* - 启航 (set sail)
*/
/**
* refer:
*
* omnibox 搜索
* GitHub demo: https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/mv2-archive/extensions/chrome_search
* Blog: https://www.cnblogs.com/cc11001100/p/12353361.html
* Debug: https://chrome.google.com/webstore/detail/omnibox-debug/nhgkpjdgjmjhgjhgjhgjhgjhgjhgjhgjhg
*/
/**
* ****************************************************************************************
*
* 搜索模式配置部分
*
* ****************************************************************************************
*/
/**
* 支持的搜索方式
*
* Notes:
* - 第一位需要保留为默认搜索方式文字
* - getSuggestions / search 方法传入参数应该是经过 getInputText 过滤前面搜索模式字符的字符串
*/
var omniboxSearchModes = [
// #############################################################################################################
{
key: "",
// 显示文字
showText: "文字",
// 搜索模式匹配
// match: function (text) { },
// 获取输入文字
getInputText: function (text, encodeText = true) {
return encodeText ? encodeXML(text) : text
},
// 搜索建议
getSuggestions: async function (text, suggest) {
// 如果前面已经有了 【[xx] 】,则先去掉
text = text.replace(/^\[.*?\]\s*/, "");
suggest([
{ content: "[百度] " + text, description: "使用 <url>[百度]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[搜狗] " + text, description: "使用 <url>[搜狗]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[必应] " + text, description: "使用 <url>[必应]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[360] " + text, description: "使用 <url>[360]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[微博] " + text, description: "使用 <url>[微博]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[知乎] " + text, description: "使用 <url>[知乎]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "[中国搜索] " + text, description: "使用 <url>[中国搜索]</url> 搜索 <match>" + text + "</match>", deletable: false },
]);
return;
// var url = "https://code.google.com/p/chromium/codesearch#search/&type=cs&q=" + query +
// "&exact_package=chromium&type=cs";
// var req = new XMLHttpRequest();
// req.open("GET", url, true);
// req.setRequestHeader("GData-Version", "2");
// req.onreadystatechange = function () {
// if (req.readyState == 4) callback(req.responseXML);
// }
// req.send(null);
// // return req;
// suggestions.forEach((suggestion) => { suggestion.deletable = false /* 用户不可删除 */ });
// /**
// * SuggestResult
// * refer: https://developer.chrome.com/docs/extensions/reference/omnibox/
// * { content, description[, deletable] }
// */
// suggest(suggestions);
// // suggest([
// // { content: "one", description: "the <match>aaa</match><url>www</url>first one", deletable: false },
// // { content: "number two", description: "the second entry", deletable: false }
// // ]);
},
// 执行搜索
search: function (text) {
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[百度]"/* 默认百度搜索 */).trim())[0].trim()
let searchText = searchInput[3].trim()
console.log("[文字搜索开始]");
console.log(" 传入参数为:", text);
console.log(" searchInput为", searchInput);
console.log(" searchType为", searchType);
console.log(" searchText为", searchText);
switch (searchType) {
default:
case "[百度]":
navigate("https://www.baidu.com/s?wd=" + encodeURIComponent(searchText), true);
break;
case "[搜狗]":
navigate("https://www.sogou.com/web?query=" + encodeURIComponent(searchText), true);
break;
case "[必应]":
navigate("https://cn.bing.com/search?q=" + encodeURIComponent(searchText), true);
break;
case "[360]":
navigate("https://www.so.com/s?q=" + encodeURIComponent(searchText), true);
break;
case "[微博]":
navigate("https://s.weibo.com/weibo?q=" + encodeURIComponent(searchText), true);
break;
case "[知乎]":
navigate("https://www.zhihu.com/search?type=content&q=" + encodeURIComponent(searchText), true);
break;
case "[今日头条]":
navigate("https://so.toutiao.com/search?dvpf=pc&keyword=" + encodeURIComponent(searchText), true);
break;
case "[中国搜索]":
navigate("http://www.chinaso.com/newssearch/all/allResults?q=" + encodeURIComponent(searchText), true);
break;
}
console.log("[文字搜索结束]");
}
},
// #############################################################################################################
{
key: "img",
// 显示文字
showText: "图片",
// 搜索模式匹配
match: function (text) {
return /^img( |:|\uff1a)?/i.test(text)
},
// 获取输入文字
getInputText: function (text, encodeText = true) {
let returnText = /^img(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
return encodeText ? encodeXML(returnText) : returnText
},
// 搜索建议
getSuggestions: async function (text, suggest) {
// 如果前面已经有了 【[xx] 】,则先去掉
text = text.replace(/^\[.*?\]\s*/, "");
suggest([
{ content: "img: [百度] " + text, description: "使用 <url>[百度图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "img: [搜狗] " + text, description: "使用 <url>[搜狗图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "img: [必应] " + text, description: "使用 <url>[必应图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "img: [360] " + text, description: "使用 <url>[360图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "img: [微博] " + text, description: "使用 <url>[微博图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "img: [今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "img: [中国搜索] " + text, description: "使用 <url>[中国搜索图片]</url> 搜索 <match>" + text + "</match>", deletable: false },
]);
return;
},
// 执行搜索
search: function (text) {
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[百度]"/* 默认百度图片搜索 */).trim())[0].trim()
let searchText = searchInput[3].trim()
console.log("[图片搜索开始]");
console.log(" 传入参数为:", text);
console.log(" searchInput为", searchInput);
console.log(" searchType为", searchType);
console.log(" searchText为", searchText);
switch (searchType) {
default:
case "[百度]":
navigate("https://image.baidu.com/search/index?tn=baiduimage&word=" + encodeURIComponent(searchText), true);
break;
case "[搜狗]":
navigate("https://pic.sogou.com/pics?query=" + encodeURIComponent(searchText), true);
break;
case "[必应]":
navigate("https://cn.bing.com/images/search?q=" + encodeURIComponent(searchText), true);
break;
case "[360]":
navigate("https://image.so.com/i?q=" + encodeURIComponent(searchText), true);
break;
case "[微博]":
navigate("https://s.weibo.com/pic?q=" + encodeURIComponent(searchText), true);
break;
case "[今日头条]":
navigate("https://so.toutiao.com/search?pd=atlas&dvpf=pc&keyword=" + encodeURIComponent(searchText), true);
break;
case "[中国搜索]":
navigate("http://www.chinaso.com/newssearch/image?q=" + encodeURIComponent(searchText), true);
break;
}
console.log("[图片搜索结束]");
}
},
// #############################################################################################################
{
key: "video",
// 显示文字
showText: "视频",
// 搜索模式匹配
match: function (text) {
return /^video( |:|\uff1a)?/i.test(text)
},
// 获取输入文字
getInputText: function (text, encodeText = true) {
let returnText = /^video(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
return encodeText ? encodeXML(returnText) : returnText
},
// 搜索建议
getSuggestions: async function (text, suggest) {
// 如果前面已经有了 【[xx] 】,则先去掉
text = text.replace(/^\[.*?\]\s*/, "");
suggest([
{ content: "video: [B站] " + text, description: "使用 <url>[哔哩哔哩动画]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [爱奇艺] " + text, description: "使用 <url>[爱奇艺]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [腾讯视频] " + text, description: "使用 <url>[腾讯视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [优酷] " + text, description: "使用 <url>[优酷]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [百度] " + text, description: "使用 <url>[百度视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [搜狗] " + text, description: "使用 <url>[搜狗视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [微博] " + text, description: "使用 <url>[微博视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [抖音] " + text, description: "使用 <url>[抖音]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [必应] " + text, description: "使用 <url>[必应视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
// 以下内容超出9个不被显示
{ content: "video: [360] " + text, description: "使用 <url>[360视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [快手] " + text, description: "使用 <url>[快手]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [知乎] " + text, description: "使用 <url>[知乎]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [搜狐] " + text, description: "使用 <url>[搜狐视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [央视网] " + text, description: "使用 <url>[央视网]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "video: [中国搜索] " + text, description: "使用 <url>[中国搜索视频]</url> 搜索 <match>" + text + "</match>", deletable: false },
]);
return;
},
// 执行搜索
search: function (text) {
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[B站]"/* 默认爱奇艺搜索 */).trim())[0].trim()
let searchText = searchInput[3].trim()
console.log("[视频搜索开始]");
console.log(" 传入参数为:", text);
console.log(" searchInput为", searchInput);
console.log(" searchType为", searchType);
console.log(" searchText为", searchText);
switch (searchType) {
default:
case "[B站]":
navigate("https://search.bilibili.com/all?keyword=" + searchText);
break;
case "[爱奇艺]":
navigate("https://so.iqiyi.com/so/q_" + encodeURIComponent(searchText), true);
break;
case "[腾讯视频]":
navigate("https://v.qq.com/x/search/?q=" + encodeURIComponent(searchText), true);
break;
case "[优酷]":
navigate("https://so.youku.com/search_video/q_" + encodeURIComponent(searchText), true);
break;
case "[百度]":
navigate("https://v.baidu.com/v?word=" + encodeURIComponent(searchText), true);
break;
case "[搜狗]":
navigate("https://v.so.com/s?q=" + encodeURIComponent(searchText), true);
break;
case "[360]":
navigate("https://tv.360kan.com/s?q=" + encodeURIComponent(searchText), true);
break;
case "[微博]":
navigate("https://s.weibo.com/video?q=" + encodeURIComponent(searchText), true);
break;
case "[抖音]":
navigate("https://www.douyin.com/search/" + encodeURIComponent(searchText) + "?type=video", true);
break;
case "[必应]":
navigate("https://cn.bing.com/videos/search?q=" + encodeURIComponent(searchText), true);
break;
case "[今日头条]":
navigate("https://so.toutiao.com/search?pd=video&dvpf=pc&keyword=" + encodeURIComponent(searchText), true);
break;
case "[知乎]":
navigate("https://www.zhihu.com/search?type=zvideo&q=" + encodeURIComponent(searchText), true);
break;
case "[快手]":
navigate("https://www.kuaishou.com/search/video?searchKey=" + encodeURIComponent(searchText), true);
break;
case "[搜狐]":
navigate("https://so.tv.sohu.com/mts?wd=" + encodeURIComponent(searchText), true);
break;
case "[央视网]":
navigate("https://search.cctv.com/search.php?type=video&qtext=" + encodeURIComponent(searchText), true);
break;
case "[中国搜索]":
navigate("http://www.chinaso.com/newssearch/video?q=" + encodeURIComponent(searchText), true);
break;
}
console.log("[视频搜索结束]");
}
},
// #############################################################################################################
{
key: "news",
// 显示文字
showText: "新闻",
// 搜索模式匹配
match: function (text) {
return /^news( |:|\uff1a)?/i.test(text)
},
// 获取输入文字
getInputText: function (text, encodeText = true) {
let returnText = /^news(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
return encodeText ? encodeXML(returnText) : returnText
},
// 搜索建议
getSuggestions: async function (text, suggest) {
// 如果前面已经有了 【[xx] 】,则先去掉
text = text.replace(/^\[.*?\]\s*/, "");
suggest([
{ content: "news: [今日头条] " + text, description: "使用 <url>[今日头条]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "news: [百度] " + text, description: "使用 <url>[百度资讯]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "news: [360] " + text, description: "使用 <url>[360资讯]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "news: [微博] " + text, description: "使用 <url>[微博]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "news: [人民网] " + text, description: "使用 <url>[人民网]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "news: [中国搜索] " + text, description: "使用 <url>[中国搜索]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "news: [快资讯] " + text, description: "使用 <url>[快资讯]</url> 搜索 <match>" + text + "</match>", deletable: false },
]);
return;
},
// 执行搜索
search: function (text) {
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[今日头条]"/* 默认今日头条搜索 */).trim())[0].trim()
let searchText = searchInput[3].trim()
console.log("[新闻搜索开始]");
console.log(" 传入参数为:", text);
console.log(" searchInput为", searchInput);
console.log(" searchType为", searchType);
console.log(" searchText为", searchText);
switch (searchType) {
default:
case "[今日头条]":
navigate("https://www.toutiao.com/search/?keyword=" + encodeURIComponent(searchText), true);
break;
case "[百度]":
navigate("https://www.baidu.com/s?tn=news&word=" + encodeURIComponent(searchText), true);
break;
case "[360]":
navigate("https://news.so.com/ns?q=" + encodeURIComponent(searchText), true);
break;
case "[微博]":
navigate("https://s.weibo.com/weibo/" + encodeURIComponent(searchText), true);
break;
case "[人民网]":
navigate("http://search.people.cn/s?keyword=" + encodeURIComponent(searchText) + "&st=0&_=" + Date.now(), true);
break;
case "[中国搜索]":
navigate("http://www.chinaso.com/newssearch/news?q=" + encodeURIComponent(searchText), true);
break;
case "[快资讯]":
navigate("https://www.360kuai.com/search?q=" + encodeURIComponent(searchText), true);
break;
}
console.log("[新闻搜索结束]");
}
},
// #############################################################################################################
{
key: "fanyi",
// 显示文字
showText: "翻译",
// 搜索模式匹配
match: function (text) {
return /^fanyi( |:|\uff1a)?/i.test(text)
},
// 获取输入文字
getInputText: function (text, encodeText = true) {
let returnText = /^fanyi(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
return encodeText ? encodeXML(returnText) : returnText
},
// 搜索建议
getSuggestions: async function (text, suggest) {
// 如果前面已经有了 【[xx] 】,则先去掉
text = text.replace(/^\[.*?\]\s*/, "");
suggest([
{ content: "fanyi: [百度] " + text, description: "使用 <url>[百度翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [有道翻译] " + text, description: "使用 <url>[有道翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [必应] " + text, description: "使用 <url>[必应词典]</url> 查词 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [腾讯] " + text, description: "使用 <url>[腾讯翻译君]</url> 翻译 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [DeepL] " + text, description: "使用 <url>[DeepL翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [金山词霸] " + text, description: "使用 <url>[金山词霸]</url> 查词 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [有道] " + text, description: "使用 <url>[有道]</url> 查词 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [360] " + text, description: "使用 <url>[360翻译]</url> 翻译 <match>" + text + "</match>", deletable: false },
{ content: "fanyi: [翻译狗] " + text, description: "使用 <url>[翻译狗]</url> 翻译 <match>" + text + "</match>", deletable: false },
// 以下内容超出9个不被显示
{ content: "fanyi: [Google] " + text, description: "使用 <url>[Google翻译]</url> 翻译 <match>" + text + "</match> Google翻译在中国大陆无法使用", deletable: false },
]);
return;
},
// 执行搜索
search: function (text) {
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[百度]"/* 默认百度翻译 */).trim())[0].trim()
let searchText = searchInput[3].trim()
console.log("[翻译搜索开始]");
console.log(" 传入参数为:", text);
console.log(" searchInput为", searchInput);
console.log(" searchType为", searchType);
console.log(" searchText为", searchText);
switch (searchType) {
default:
case "[百度]":
// 百度翻译中英文会自动识别,所以不需要手动判断
navigate("https://fanyi.baidu.com/#en/zh/" + encodeURIComponent(searchText), true);
break;
case "[有道翻译]":
// 后面参数通过注入的js代码获取并在网页加载完后填入到翻译框中点击翻译按钮
navigate("https://fanyi.youdao.com/?__bitdance_extension__=" + encodeURIComponent(searchText), true);
break;
case "[必应]":
navigate("https://cn.bing.com/dict/search?q=" + encodeURIComponent(searchText), true);
break;
case "[腾讯]":
// 网页加载好后自动点击翻译按钮
navigate("https://fanyi.qq.com/?text=" + encodeURIComponent(searchText), true);
break;
case "[DeepL]":
let hasChineseChar = /.*[\u4e00-\u9fa5]+.*$/.test(searchText)
navigate("https://www.deepl.com/translator#" + (hasChineseChar ? "zh/en/" : "en/zh/") + encodeURIComponent(searchText), true);
break;
case "[金山词霸]":
navigate("https://www.iciba.com/word?w=" + encodeURIComponent(searchText), true);
break;
case "[有道]":
navigate("https://www.youdao.com/w/" + encodeURIComponent(searchText), true);
break;
case "[360]":
navigate("https://fanyi.so.com/#" + encodeURIComponent(searchText), true);
break;
case "[翻译狗]":
navigate("https://www.fanyigou.com/trans/totran/tranText.html?text=" + encodeURIComponent(searchText), true);
break;
case "[Google]":
navigate("https://translate.google.cn/?text=" + encodeURIComponent(searchText), true);
break;
}
console.log("[翻译搜索结束]");
}
},
// #############################################################################################################
{
key: "paper",
// 显示文字
showText: "学术论文",
// 搜索模式匹配
match: function (text) {
return /^paper( |:|\uff1a)?/i.test(text)
},
// 获取输入文字
getInputText: function (text, encodeText = true) {
let returnText = /^paper(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
return encodeText ? encodeXML(returnText) : returnText
},
// 搜索建议
getSuggestions: async function (text, suggest) {
// 如果前面已经有了 【[xx] 】,则先去掉
text = text.replace(/^\[.*?\]\s*/, "");
suggest([
{ content: "paper: [知网] " + text, description: "使用 <url>[中国知网]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "paper: [万方] " + text, description: "使用 <url>[万方数据]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "paper: [维普] " + text, description: "使用 <url>[维普期刊]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "paper: [百度] " + text, description: "使用 <url>[百度学术]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "paper: [必应] " + text, description: "使用 <url>[必应学术]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "paper: [搜狗] " + text, description: "使用 <url>[搜狗学术]</url> 搜索 <match>" + text + "</match>", deletable: false },
{ content: "paper: [谷歌] " + text, description: "使用 <url>[谷歌学术]</url> 搜索 <match>" + text + "</match> (谷歌学术在中国大陆无法使用)", deletable: false },
]);
return;
},
// 执行搜索
search: function (text) {
let searchInput = /^(\[.*?\])?( )?(.*)$/.exec(text)
let searchType = /^\[(.*?)\]$/.exec((searchInput[1] ?? "[今日头条]"/* 默认今日头条搜索 */).trim())[0].trim()
let searchText = searchInput[3].trim()
console.log("[学术论文搜索开始]");
console.log(" 传入参数为:", text);
console.log(" searchInput为", searchInput);
console.log(" searchType为", searchType);
console.log(" searchText为", searchText);
switch (searchType) {
default:
case "[知网]":
// 后面参数通过注入的js代码获取并在网页加载完后填入到搜索框中点击搜索按钮
navigate("https://www.cnki.net/?__bitdance_extension__=" + encodeURIComponent(searchText), true);
break;
case "[万方]":
navigate("https://s.wanfangdata.com.cn/paper?q=" + encodeURIComponent(searchText), true);
break;
case "[维普]":
// 后面参数通过注入的js代码获取并在网页加载完后填入到搜索框中点击搜索按钮
navigate("http://qikan.cqvip.com/?__bitdance_extension__=" + encodeURIComponent(searchText), true);
break;
case "[百度]":
navigate("https://xueshu.baidu.com/s?wd=" + encodeURIComponent(searchText), true);
break;
case "[必应]":
navigate("https://cn.bing.com/academic/search?q=" + encodeURIComponent(searchText), true);
break;
case "[搜狗]":
navigate("https://scholar.sogou.com/xueshu?query=" + encodeURIComponent(searchText), true);
break;
case "[Google]":
navigate("https://scholar.google.com/scholar?q=" + encodeURIComponent(searchText), true);
break;
}
console.log("[学术论文搜索结束]");
}
},
// #############################################################################################################
// {
// key: "yn",
// // 显示文字
// showText: "网页内搜索(Todo)",
// // 搜索模式匹配
// match: function (text) {
// return /^yn( |:|\uff1a)?/i.test(text)
// },
// // 获取输入文字
// getInputText: function (text, encodeText = true) {
// let returnText = /^yn(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
// return encodeText ? encodeXML(returnText) : returnText
// },
// // 搜索建议
// getSuggestions: async function (text, suggest) {
// return;
// },
// // 执行搜索
// search: function (text) {
// }
// },
// #############################################################################################################
// {
// key: "re",
// // 显示文字
// showText: "网页内正则表达式搜索(Todo)",
// // 搜索模式匹配
// match: function (text) {
// return /^re( |:|\uff1a)?/i.test(text)
// },
// // 获取输入文字
// getInputText: function (text, encodeText = true) {
// let returnText = /^re(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
// return encodeText ? encodeXML(returnText) : returnText
// },
// // 搜索建议
// getSuggestions: async function (text, suggest) {
// return;
// },
// // 执行搜索
// search: function (text) {
// }
// },
// #############################################################################################################
// {
// key: "ls",
// // 显示文字
// showText: "历史记录(Todo)",
// // 搜索模式匹配
// match: function (text) {
// return /^ls( |:|\uff1a)?/i.test(text)
// },
// // 获取输入文字
// getInputText: function (text, encodeText = true) {
// let returnText = /^ls(:| |\uff1a)?(.*)$/i.exec(text)[2].trim()
// return encodeText ? encodeXML(returnText) : returnText
// },
// // 搜索建议
// getSuggestions: async function (text, suggest) {
// return;
// },
// // 执行搜索
// search: function (text) {
// function onGot(historyItems) {
// for (item of historyItems) {
// console.log(item.url);
// console.log(new Date(item.lastVisitTime));
// }
// }
// var searching = browser.history.search({ text: text, startTime: 0 });
// searching.then(onGot);
// }
// },
// #############################################################################################################
// {
// key: "boss",
// // 显示文字
// showText: "召唤“学生助手”",
// // 搜索模式匹配
// match: function (text) {
// // return text.trim() == "boss"
// return /^boss( |:|\uff1a)?$/i.test(text)
// },
// // 获取输入文字
// getInputText: (text) => "回车执行",
// // 搜索建议
// getSuggestions: async function (text, suggest) {
// return;
// },
// // 执行搜索
// search: function (text) {
// }
// }
]
/**
* ****************************************************************************************
*
* 全局变量定义部分
*
* ****************************************************************************************
*/
// 当前匹配的搜索模式的下标
var currentSearchModeIndex = 0;
// 当前正在向服务端进行的请求
var currentRequest = null;
//
var ajaxUrl = "https://www.baidu.com/s?wd=";
/**
* ****************************************************************************************
*
* 搜索模式配置部分
*
* ****************************************************************************************
*/
/**
* 用户开始输入文本
*/
chrome.omnibox.onInputStarted.addListener(function () {
console.log("chrome.omnibox.onInputStarted");
updateDefaultSuggestion('');
});
/**
* 搜索框失去焦点
*/
chrome.omnibox.onInputCancelled.addListener(function () {
console.log("chrome.omnibox.onInputCancelled");
updateDefaultSuggestion('');
});
/**
* 输入框文本改变事件
*/
chrome.omnibox.onInputChanged.addListener(function (text, suggest) {
console.log("chrome.omnibox.onInputChanged", text);
// 停止上一次搜索行为
if (currentRequest != null) {
currentRequest.onreadystatechange = null;
currentRequest.abort();
currentRequest = null;
}
// 更新输入框回显提示信息
updateDefaultSuggestion(text);
// 如果啥也没有输入就返回
if (text.trim() == '')
return;
// 访问后端服务获得搜索建议
var currentSearchMode = omniboxSearchModes[currentSearchModeIndex];
currentSearchMode.getSuggestions(currentSearchMode.getInputText(text), suggest);
});
/**
* 用户输入完成按下回车键
*/
chrome.omnibox.onInputEntered.addListener(function (text) {
console.log("chrome.omnibox.onInputEntered");
// 更新输入框回显提示信息
// 注意这里必须还要更新一次因为用户在输入时使用上下键选择suggest项目时会触发 chrome.omnibox.onInputChanged 事件
// 如果不执行,那么输入 ss img 之后上下选择对应搜索,按回车会被解析为文字搜索,而不是图片搜索
updateDefaultSuggestion(text);
var searchMode = omniboxSearchModes[currentSearchModeIndex];
var searchText = searchMode.getInputText(text);
searchMode.search(searchText);
console.log("用户输入:" + text);
});
/**
* ****************************************************************************************
*
* 公共函数部分
*
* ****************************************************************************************
*/
/**
* & < > 等特殊字符转义但保留中文不进行转义
*
* 测试通过: [ re 百度&nbsp;<>!@#$%%^&*()_+-=[]{}|\:;'",./? ]
*
* refer: https://www.javaroad.cn/questions/108186
* @param string str
* @returns
*/
function encodeXML(str) {
var holder = document.createElement('div');
holder.textContent = str;
return holder.innerHTML;
}
/**
* 将当前标签页导航到指定Url / 或者新建标签页
*
* @param String url 要导航到的url
* @param bool openInNewTab 是否打开新标签页
*/
function navigate(url, openInNewTab = false) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (!openInNewTab || isCurrentNewTab()) {
// 如果不在新标签页打开,或者当前标签页是新标签页
chrome.tabs.update(tabs[0].id, { url: url });
} else {
// 如果在新标签页打开,且当前标签页不是新标签页
chrome.tabs.create({ url: url });
}
});
}
/**
* 获取当前是否是新标签页
*/
function isCurrentNewTab() {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (tabs && tabs.length > 0 && !!tabs[0].url && /^(.*?):\/\/newtab\/$/.test(tabs[0].url)) {
console.log("当前标签页是新标签页");
return true;
}
else {
console.log("当前标签页不是新标签页");
return false;
}
});
}
/**
* 更新下拉框中提示
* @param String text 用户输入文本
*/
function updateDefaultSuggestion(text) {
var description = [
'<match><url>搜索方式</url></match>',
'<dim> [ </dim>',
'' /* 文字搜索 显示文字占位 */
];
// 如果用户输入不为空,先假设为文字搜索,如果后面匹配上了其他搜索方式,则更新
let isPlaintext = !!text.trim().length;
currentSearchModeIndex = 0; // 初始化搜索方式下标
// 默认第 0 个为文字搜索,除此之外的搜索方式如果都没有匹配到,则显示文字搜索
for (var i = 1, keyword; i < omniboxSearchModes.length; i++) {
keyword = omniboxSearchModes[i];
// 分隔符
description.push('<dim> \| </dim>');
// 通过用户输入文本匹配搜索方式
if (keyword.match(text)) {
// 是当前这种搜索模式
isPlaintext = false; // 说明不是文字搜索
currentSearchModeIndex = i; // 记录当前搜索模式的下标
description.push('<match>' + keyword.showText + '' + keyword.getInputText(text) + '</match>');
} else {
// 不是当前这种搜索模式
description.push('<dim>' + keyword.key + ": " + keyword.showText + '</dim>');
}
}
description.push('<dim> ] </dim>');
if (text.trim().length != 0) {
description[2] = isPlaintext ? ('<match>' + omniboxSearchModes[0].showText + '' + text.trim() + '</match>') : ('<dim>' + omniboxSearchModes[0].showText + '</dim>');
} else {
// 用户什么也没输入时,就高亮显示文字搜索关键字
description[2] = '<match>' + omniboxSearchModes[0].showText + '</match>';
}
console.log("[更新下拉框提示开始]");
console.log(" text", text);
console.log(" 当前匹配搜索模式:", omniboxSearchModes[currentSearchModeIndex].showText);
console.log(" isPlaintext", isPlaintext);
// console.log(description.join(''));
console.log("[更新下拉框提示结束]");
chrome.omnibox.setDefaultSuggestion({
description: description.join('')
});
// var isRegex = /^re:/.test(text);
// var isFile = /^file:/.test(text);
// var isHalp = (text == 'halp');
// var isPlaintext = text.length && !isRegex && !isFile && !isHalp;
// var description = '<match><url>搜索方式</url></match><dim> [ </dim>';
// description += isPlaintext ? ('<match>' + text + '</match>') : '文字';
// description += '<dim> | </dim>';
// description += isRegex ? ('<match>' + text + '</match>') : 're: 正则';
// description += '<dim> | </dim>';
// description += isFile ? ('<match>' + text + '</match>') : 'file:文件';
// description += '<dim> | </dim>';
// description += isHalp ? '<match>halp</match>' : 'halp';
// description += '<dim> ]</dim>';
// chrome.omnibox.setDefaultSuggestion({
// description: description
// });
}

View File

@ -0,0 +1,4 @@
console.log("[BitDance extension] 学生助手插件 - 腾讯翻译君自动点击翻译模块加载成功");
window.onload = () => {
$(".language-translate-button")[0].click()
}

View File

@ -0,0 +1,31 @@
console.log("[BitDance extension] 学生助手插件 - 有道翻译自动填入模块加载成功");
// refer: https://www.cnblogs.com/chen-lhx/p/5198612.html
$.extend({
getUrlVars: function () {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function (name) {
return $.getUrlVars()[name];
}
});
window.onload = () => {
let transText = $.getUrlVar('__bitdance_extension__');
if (!transText || transText.trim() == "") return
console.log("[BitDance extension] 学生助手插件 - 有道翻译自动填入模块 - 翻译文本为:", transText);
document.getElementsByTagName("textarea")[0].value = decodeURIComponent(transText)
document.getElementById("transMachine").click()
// 参数获取完成后,清除掉页面参数
// History.replaceState() refer: https://developer.mozilla.org/zh-CN/docs/Web/API/History/replaceState
history.replaceState({}, "", "/");
}

View File

@ -0,0 +1,27 @@
console.log("[BitDance extension] 学生助手插件 - 维普期刊自动搜索模块加载成功");
// refer: https://www.cnblogs.com/chen-lhx/p/5198612.html
$.extend({
getUrlVars: function () {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function (name) {
return $.getUrlVars()[name];
}
});
window.onload = () => {
let transText = $.getUrlVar('__bitdance_extension__');
if (!transText || transText.trim() == "") return
console.log("[BitDance extension] 学生助手插件 - 维普期刊自动搜索模块 - 模块文本为:", transText);
document.getElementById("searchKeywords").value = decodeURIComponent(transText)
document.getElementById("btnSearch").click()
}

View File

@ -0,0 +1,27 @@
console.log("[BitDance extension] 学生助手插件 - 中国知网自动搜索模块加载成功");
// refer: https://www.cnblogs.com/chen-lhx/p/5198612.html
$.extend({
getUrlVars: function () {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function (name) {
return $.getUrlVars()[name];
}
});
window.onload = () => {
let transText = $.getUrlVar('__bitdance_extension__');
if (!transText || transText.trim() == "") return
console.log("[BitDance extension] 学生助手插件 - 中国知网自动搜索模块 - 模块文本为:", transText);
document.getElementById("txt_SearchText").value = decodeURIComponent(transText)
document.querySelector(".search-btn").click()
}

View File

@ -0,0 +1 @@
console.log("[BitDance extension] 学生助手插件 - 高级搜索功能模块加载成功")

View File

@ -1,11 +1,50 @@
chrome.contextMenus.create({
id: 'bitdance',
title: '学生助手' //,
// onclick: function () {
// alert("[BitDance extension] 学生助手插件 - 已点击菜单")
// }
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);
console.log(`进入 assets\js\background.js 中的onMessage Listener`)
// 抛给下一个Listener
sendResponse();
console.log(`离开 assets\js\background.js 中的onMessage Listener`)
return true;
/**
* refer:
* https://stackoverflow.com/questions/4924125/can-chrome-extension-background-pages-have-multiple-listeners
* https://developer.chrome.com/extensions/runtime#event-onMessage
* https://blog.csdn.net/lamp_yang_3533/article/details/100174074
*/
})
//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.'
});
}
chrome.contextMenus.create({
id: 'bitdance-advanced-search-notification',
title: 'Notification',
parentId: 'bitdance',
onclick: function (info) {
showNotification()
}
})

View File

@ -1 +1 @@
console.log("[BitDance extension] 学生助手插件已启用")
console.log("[BitDance extension] 学生助手插件已启用")

View File

@ -0,0 +1,112 @@
window.onload = function(){
console.log("[BitDance extension] 学生助手插件 - 确认跳转页直接跳转模块加载成功");
chrome.storage.sync.get("linkOpen", ({ linkOpen })=>{
if(linkOpen){
let locHost = location.host,locHref = location.href;
let methods = {
http(link, s = false) {
return link.startsWith("http")
? link
: (s ? "https://" : "http://") + link;
},
};
let RedirectPage = {
sites: {
"c.pc.qq.com": {
include: "middlem.html?pfurl=",
selector: "#url",
},
"docs.qq.com": {
include: "scenario/link.html?url=",
selector: "span.url-src",
timeout: 500,
},
"www.tianyancha.com": {
include: "security?target=",
selector: "div.security-link",
},
"jump.bdimg.com": {
include: "safecheck/index?url=",
selector: "div.warning_info.fl>a",
},
"jump2.bdimg.com": {
include: "safecheck/index?url=",
selector: "div.warning_info.fl>a",
},
"www.chinaz.com": {
include: "go.shtml?url=",
selector: "div.link-bd__text",
},
"www.douban.com": {
include: "link2/?url=",
selector: "a.btn-redir",
},
"iphone.myzaker.com" : {
include: "zaker/link.php?",
selector: "a.btn",
},
"www.itdaan.com": {
include: "link/",
selector: "a.c-footer-a1",
},
"link.csdn.net": {
include: "?target=",
selector: "a.loading-btn",
timeout: 100,
},
"link.zhihu.com":{
include :"?target=",
selector : "a.button"
},
"link.juejin.cn": {
include: "?target=",
selector: 'p[style="margin: 0px;"]',
},
"www.jianshu.com": {
include: "go-wild?ac=2&url=",
selector: 'div[title^="http"], div[title^="www"]',
},
// QQ、腾讯文档、天眼查、百度贴吧、站长之家、豆瓣、Zaker、开发者知识库、CSDN、知乎、掘金、简书etc...
},
redirect(host){
let site = this.sites[host];
if (site) {
let include = host + "/" + site.include;
if (locHref.includes(include) || site.match && locHref.match(site.match)) {
let target = document.querySelector(site.selector);
if (target.length) location.replace(target.href || target.innerText);
}
}
}
}
setTimeout(url(),200);
function url(){
let flag = false;
if(locHref.includes(RedirectPage.sites[locHost].include)){
locHref = locHref.split(RedirectPage.sites[locHost].include);
flag = true;
}
if(flag){
location.replace(decodeURIComponent(locHref[1]));
}else{
//改进
if(RedirectPage.sites[locHost].selector){
let target = document.querySelector(RedirectPage.sites[locHost].selector);
location.replace(target.href || target.innerText)
}
}
}
//两种方案 默认不阻止重定向 阻止重定向直接跳转
}
})
}

View File

@ -0,0 +1,25 @@
/**
* TODO: 实现CSDN自动展开全文
*/
$(function() {
console.log("[BitDance extension] 学生助手插件 - CSDN阅读全文自动展开模块加载成功");
// 全文自动展开
function removeDOM(querySelector) {
let element = document.querySelector(querySelector)
if (element != null) {
element.parentNode.removeChild(element);
}
}
removeDOM(".hide-article-box");
$(".article_content").removeAttr('style');
window.onload = () => {
// 代码块自动展开
document.querySelectorAll("pre").forEach(targetNode => {
removeDOM(".hide-preCode-box");
if (targetNode.classList.contains("set-code-hide")) {
targetNode.classList.remove("set-code-hide");
}
})
}
})

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
/**
* TODO: 鼠标点击效果
*/
$(function() {
console.log("[BitDance extension] 学生助手插件 - 点击特效模块加载成功");
// 每次改变开关状态时刷新页面使功能及时生效
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(`进入 assets\js\mouse-effects\click.js 中的onMessage Listener`)
if (request.info === 'click') {
location.reload();
sendResponse('Reload page');
}
console.log(`离开 assets\js\mouse-effects\click.js 中的onMessage Listener`)
return true;
})
// 控制功能是否开启
chrome.storage.sync.get('clickState3', function(budget) {
// 得到按钮开关状态
if (budget.clickState3 == false || budget.clickState3 == undefined) {
// console.log('click功能启动');
var hearts = [];
walk();
// 走起(初始化)
function walk() {
// 灵魂 css
css(".heart{width: 10px;height: 10px;position: fixed;background: pink;transform: rotate(45deg);}.heart::after,.heart::before{position: absolute;content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;}.heart::after{top: -5px;}.heart::before{left: -5px;}");
attachEvent();
gameloop();
}
// 动画效果
function gameloop() {
for (var i = 0; i < hearts.length; i++) {
if (hearts[i].alpha <= 0) {
document.body.removeChild(hearts[i].el);
hearts.splice(i, 1);
continue;
}
hearts[i].y--;
hearts[i].scale += 0.004;
hearts[i].alpha -= 0.013;
hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
}
// refer: https://developer.mozilla.org/zh-CN/docs/Web/API/Window/requestAnimationFrame
requestAnimationFrame(gameloop);
}
function attachEvent() {
// 点击触发特效(♥)
window.onclick = function(event) {
createHeart(event);
}
}
function createHeart(event) {
// 创建一个 div 并指定类名为 heart
var d = document.createElement("div");
d.className = "heart";
/**
* @param el: 每个 div 的标识
* @param x,y: 当前鼠标位置信息
* @param scale: 放大系数
* @param alpha: 透明度
* @param color: 背景颜色
*/
hearts.push({
el: d,
x: event.clientX,
y: event.clientY,
scale: 1,
alpha: 1,
color: randomColor()
});
document.body.appendChild(d);
}
// 给网页加个 style 标签
function css(css) {
// 创建 style 标签
var style = document.createElement("style");
style.type = "text/css";
// css 内容注入
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);
}
// 生成随机颜色
function randomColor() {
return "rgb(" + (Math.random() * 255) + "," + (Math.random() * 255) + "," + (Math.random() * 255) + ")";
}
}
});
})

View File

@ -0,0 +1,33 @@
/**
* TODO: 鼠标样式
*/
$(function() {
console.log("[BitDance extension] 学生助手插件 - 鼠标样式模块加载成功");
// 每次改变开关状态时刷新页面使功能及时生效
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log(`进入 assets\js\mouse-effects\mouse-style.js 中的onMessage Listener`)
if (request.info === 'mouse') {
location.reload();
sendResponse('Reload page');
}
console.log(`离开 assets\js\mouse-effects\mouse-style.js 中的onMessage Listener`)
return true;
})
// 控制功能是否开启
chrome.storage.sync.get('clickState2', function(budget) {
// 得到按钮开关状态
if (budget.clickState2 == false || budget.clickState2 == undefined) {
$('*').hover(function() {
$(this).css("cursor", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c%0A6QAABPxJREFUWEe9lltIalkYx9feak1hDBonIvVM0ZyKLmAM3YyIqB6KCgrK%0Abj710G1gKooJJrCYiB4q6qHefIgoKoaChpiieojQJIWiy0GygzaO0RVhSDTb%0Ae+1hOSlb3d56aL+Iur/1/db3/77/Whj4/6kGAOgAAPq37x/2gQEAyrRa7V9s%0ANhuTSqXk5eXlGUVRTR8FgwC+HB0dfc3JyWG7tq3RaAiZTAY/AgYBgNTU1Bed%0AThfBVHcE09DQQFxfX1+EUJkoAMAnAMDfoWroBMAwTAsh/ClYUACYIQzDfkeg%0ACQkJ5Pz8PG6xWB4oihIEW9MJwCRDsECVSoUqQ97c3BgrKioSNzc3I+kxZrMZ%0AikQinKIoVw7GJd1/BpLBH8zr6ysVHx9Pra2tUS0tLS9CoRBfW1vjJCQksFDM%0Azs4OUV1dPffy8vKLvzXcAKHKQF9ILpeTVVVVFL2B9/f3SQSTlJSEraysRAiF%0AQlagKtDL4zMNwWSoqakhNzY2nLtlehBMSUkJAtgDAKDRfvB+z0OfcGUYHx9/%0ALS4uxgoKCtwj7J0Ax3EAIQR7e3tEc3MzcX9/r6TDeAC8RwYulwufn59xpgos%0ALi46Li4u8LGxMQ9ABINM7+npSeTdoWHLMDIyQqhUKmp7e5tDhzg9PSXFYjEG%0AIWSEQw0cExMz5TMiiYmJNoPB8F0w/en/Ly0tvba2tnIKCgpIkUhEra6u4vn5%0A+VClUjFKgyojk8msFEXxfQDeIwMdBu2Mw+Ewzr5WqyXz8vIICOGPAIB/nCbI%0AsNMvSqXyq0Qi8dtYTNVBLri6usoYY7FYkCkRVqu1CtkDPZ6RVCAQ2A0GQ8To%0A6Cg8Pj4GEokEDg4OemjsDVFbW0vy+XxSoVC4zxRUjeTkZIfJZPoVADDDBM4I%0AgGGYjsfjfdna2oLIZA4PD4ny8nJ8YGAAyuXyoCOHEvX19dlnZ2f/dDgcDYH6%0AiQlgqLKycmh4eJhFdzi0SFlZmaO9vZ2qr6/38H2RSARvb28JkiQj5ubmHB0d%0AHc4qZGdn205OTlJceodUAQzDKGQcaWlpdp1O5zMNLmPp6uoiULPNzMyw0G96%0AvZ64uroCubm5OI/Hc49eMAjvCkRJpdJ/l5eX2fn5+Xa1Wu0DUFhYSCqVSqf9%0ASiQSQq1Ws6Ojo6FCoYBSqZRRnjeIH4JaMQDgc29v7+XU1FSk0WgkHx4ePA4a%0AlLSxsZFYWFhg0UetqamJnJiYwAQCAaPp0OTwgfDpAdTJT09PzoWYZMBxHPpz%0At2DmlZWVZTs/P/eAYDIis8lkike7KSoqsh0cHKBrlvNB9trW1gY0Go37BOzp%0A6bFNT0+73wkXwt8YIm8nMjIyMLPZ7JThzT7Z9N2jOedyuX+kp6dXHR8fvwvC%0A73UpMjJyxuFw/AwAcMoxODhIeJ9qSUlJdqPRiBILxWLxZTgQKSkpdr1eHxXw%0AvvZWzl2Kokq9S4vslc/n99EcLiyIycnJ1/7+/u9DAfi8u7v7rbS01GPEuFyu%0Aw2q1ehgSupKLxeLrYJVYX1931NXVyQEA46EAgLi4ONvd3Z3bE9CplpOTU+F9%0AsLxVKSAEPbm/05CpkT1kYLFYLxDCQHeGT5mZmddnZ2cejemdPBwAtwxoGlpb%0AW5MD+burEnQIpuThAIDY2Fj74+NjJI7jFnSTCTbvdIjOzk68u7t7GGnuHRdS%0AD7gWw3H8NwhhT4jJ6a8hKWxMcf8BWQiA/lSw+WUAAAAASUVORK5CYII=), crosshair");
});
} else {
('*').hover(function() {
$(this).css("cursor", "auto");
});
}
})
})

View File

@ -0,0 +1,81 @@
$(function() {
// 获取开关状态
chrome.storage.sync.get('clickState2', function(budget) {
// console.log(budget.clickState);
// 获取页面节点
let input = document.querySelector("#button-2");
// 改变开关状态(保持与上次设置时一致)
input.checked = budget.clickState2;
});
// 获取开关状态
chrome.storage.sync.get('clickState3', function(budget) {
// console.log(budget.clickState);
// 获取页面节点
let input = document.querySelector("#button-3");
// 改变开关状态(保持与上次设置时一致)
input.checked = budget.clickState3;
});
// 点击开关时改变按钮状态
$("#button-2").click(function() {
// 获取开关
let checked = $("#button-2");
// 持久化存储开关状态
chrome.storage.sync.set({ 'clickState2': checked[0].checked });
console.log('mouse success');
// 自动刷新页面
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
console.log(tabs);
let message = {
info: 'reload'
}
chrome.tabs.sendMessage(tabs[0].id, message, res => {
console.log(res);
})
})
});
// 点击开关时改变按钮状态
$("#button-3").click(function() {
// 获取开关
let checked = $("#button-3");
// 持久化存储开关状态
chrome.storage.sync.set({ 'clickState3': checked[0].checked });
console.log('click success');
// 自动刷新页面
chrome.tabs.query({
active: true,
currentWindow: true
}, (tabs) => {
console.log(tabs);
let message = {
info: 'reload'
}
chrome.tabs.sendMessage(tabs[0].id, message, res => {
console.log(res);
})
})
})
// Direct Url
const btnDirectUrl = document.querySelector("#btnDirectUrl");
chrome.storage.sync.get("linkOpen", ({ linkOpen }) => {
btnDirectUrl.checked = !linkOpen;
});
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]);
})
});
})

View File

@ -1,29 +1,98 @@
{
"name": "BitDance浏览器小插件",
"name": "学生助手",
"version": "0.1.0",
"description": "BitDance Chrome Extension",
"manifest_version": 2,
"_locale": "zh_CN",
"omnibox": {
"keyword": "ss"
},
"icons": {
"16": "assets/image/logo.png",
"48": "assets/image/logo.png",
"128": "assets/image/logo.png"
},
"background": {
"scripts": [
"assets/js/background.js"
"assets/js/lib/jquery.min.js",
"assets/js/background.js",
"assets/html/pomodoro/background.js",
"assets/js/advanced-search/background.js",
"assets/html/screenshot/background.js"
]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
"<all_urls>",
"*://*/*"
],
"js": [
"assets/js/content.js"
"assets/js/lib/jquery.min.js",
"assets/js/content.js",
"assets/js/direct-url/url.js",
"assets/js/mouse-effects/click.js",
"assets/js/mouse-effects/mouse-style.js",
"assets/js/advanced-search/content.js"
],
"css": []
"css": [],
"run_at": "document_start"
},
{
"matches": [
"*://blog.csdn.net/*"
],
"js": [
"assets/js/lib/jquery.min.js",
"assets/js/expand-full-text/expand.js"
],
"run_at": "document_start"
},
{
"matches": [
"*://fanyi.qq.com/*"
],
"js": [
"assets/js/lib/jquery.min.js",
"assets/js/advanced-search/content-helper/fanyi.qq.com.js"
],
"run_at": "document_start"
},
{
"matches": [
"*://fanyi.youdao.com/*"
],
"js": [
"assets/js/lib/jquery.min.js",
"assets/js/advanced-search/content-helper/fanyi.youdao.com.js"
],
"run_at": "document_start"
},
{
"matches": [
"*://www.cnki.net/*"
],
"js": [
"assets/js/lib/jquery.min.js",
"assets/js/advanced-search/content-helper/www.cnki.net.js"
],
"run_at": "document_start"
},
{
"matches": [
"*://qikan.cqvip.com/*",
"*://lib.cqvip.com/*"
],
"js": [
"assets/js/lib/jquery.min.js",
"assets/js/advanced-search/content-helper/qikan.cqvip.com.js"
],
"run_at": "document_start"
}
],
"browser_action": {
"default_icon": "assets/image/icon_disabled.png",
"default_icon": "assets/image/logo.png",
"default_popup": "popup.html",
"default_title": "这是一个默认title"
"default_title": "召唤“学生助手” (Alt+,)"
},
"commands": {
"_execute_browser_action": {
@ -34,13 +103,17 @@
"description": "打开 [学生助手] 插件"
}
},
"web_accessible_resources": [
"/assets/image/*",
"/assets/html/screenshot/images/*"
],
"permissions": [
"background",
"contextMenus",
"storage",
"unlimitedStorage",
"webRequest",
"webRequestBlocking",
"tabs"
"tabs",
"activeTab",
"notifications"
]
}
}

View File

@ -1,18 +1,60 @@
<!doctype html>
<html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BitDance</title>
<link href="assets/css/main.css" type="text/css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生助手</title>
<link href="assets/css/main.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="popup">
<div class="panel">
<p>Hello world!</p>
</div>
</div>
<script src="assets/js/common/jquery.min.js"></script>
<script src="assets/js/popup.js"></script>
<div id="popup">
<header>
<img src="assets/image/logo.png" alt="Logo">
</header>
<div class="article">
<ul>
<li>
<div id="expand">
</div>
</li>
<li>
<div id="mouse-style">
<span>鼠标样式</span>
<div class="button">
<input type="checkbox" id="button-2" class="checkbox" />
<div class="knobs"></div>
<div class="layer"></div>
</div>
</div>
</li>
<li>
<div id="click-per">
<span>点击特效</span>
<div class="button">
<input type="checkbox" id="button-3" class="checkbox" />
<div class="knobs"></div>
<div class="layer"></div>
</div>
</div>
</li>
<li>
<div id="click-per">
<span>确认访问页自动跳转</span>
<div class="button">
<input type="checkbox" id="btnDirectUrl" class="checkbox" />
<div class="knobs"></div>
<div class="layer"></div>
</div>
</div>
</li>
</ul>
</div>
<button id="btnScreenshot">截图</button>
<iframe src="assets/html/pomodoro/popup.html" id="pomodoro" style="border: 0; height: 400px;"></iframe>
</div>
<script src="assets/js/lib/jquery.min.js"></script>
<script src="assets/js/popup.js"></script>
</body>
</html>
</html>