Skip to content

Commit

Permalink
V1.3.1
Browse files Browse the repository at this point in the history
优化逻辑
  • Loading branch information
Huozzzy committed Apr 24, 2022
1 parent 77263ac commit 172e74e
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 279 deletions.
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
本插件基于原开源插件`学习小熊`的版本,针对新的文章视频阅读规则开发的二次版本。

## 更新说明
v1.3.0(2022-03-09):

优化答题。
此版本为 Manifest V2 的最后一次更新,下一版本将迁移至 V3 版本插件。


## 致谢
此处感谢原作者:CN1984
原作者版本链接在此:[学习小熊](https://github.com/CN1984/LearningThePooh)
由于原作最后更新时间为2019年,且我提交的PR一直没有合并,本人大胆推测原作者已停止更新,故开发现版本。
若有侵权,请原作者及时联系我,我将立即停止此项目。
v1.3.1(2022-04-24):

优化部分逻辑。

## 下载
* [最新发布](https://github.com/Huozzzy/Learning-Learner/releases/download/release/Learning-Learner.crx)
Expand Down
146 changes: 73 additions & 73 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function getPointsData(callback) {
let res = JSON.parse(xhr.responseText);
if (res.hasOwnProperty("code") && parseInt(res.code) === 200) {
if (checkScoreAPI(res)) {
if (!isMobile) {
// if (!isMobile) {
chrome.browserAction.setBadgeText({ "text": res.data.totalScore.toString() });
}
// }
if (typeof callback === "function") {
callback(res.data);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ function getChannelData(type, callback) {
shuffle(channel[type]);
channelArr = channel[type][0].split('|');

if (!isMobile) {
// if (!isMobile) {
chrome.windows.get(runningWindowId, { "populate": true }, function (window) {
if (typeof window !== "undefined") {
chrome.tabs.sendMessage(window.tabs[window.tabs.length - 1].id, {
Expand All @@ -100,12 +100,12 @@ function getChannelData(type, callback) {
});
}
});
} else {
chrome.tabs.sendMessage(runningTabId, {
"method": "redirect",
"data": channelArr[1]
});
}
// } else {
// chrome.tabs.sendMessage(runningTabId, {
// "method": "redirect",
// "data": channelArr[1]
// });
// }

setTimeout(function () {
let xhr = new XMLHttpRequest();
Expand Down Expand Up @@ -242,7 +242,7 @@ function autoEarnPoints(timeout) {

}

if (!isMobile) {
// if (!isMobile) {
if (url && scoreTabId && runningWindowId) {
chrome.windows.get(runningWindowId, { "populate": true }, function (window) {
if (typeof window !== "undefined") {
Expand All @@ -256,18 +256,18 @@ function autoEarnPoints(timeout) {
} else {
closeWindow();
}
} else {
if (url && scoreTabId && runningTabId) {
chrome.tabs.sendMessage(runningTabId, {
"method": "redirect",
"data": url
});
autoEarnPoints(newTime);
} else {
chrome.tabs.remove(runningTabId);
chrome.tabs.remove(scoreTabId);
}
}
// } else {
// if (url && scoreTabId && runningTabId) {
// chrome.tabs.sendMessage(runningTabId, {
// "method": "redirect",
// "data": url
// });
// autoEarnPoints(newTime);
// } else {
// chrome.tabs.remove(runningTabId);
// chrome.tabs.remove(scoreTabId);
// }
// }
});
}, timeout);
}
Expand Down Expand Up @@ -299,7 +299,7 @@ function shuffle(array) {

//通知
function notice(title, message = "") {
if (!isMobile) {
// if (!isMobile) {
chrome.notifications.create({
"type": "basic",
"iconUrl": "img/Pikachu-128.png",
Expand All @@ -310,9 +310,9 @@ function notice(title, message = "") {
chrome.notifications.clear(notificationId);
}, 5000);
});
} else {
alert(title + (message ? "\n" + message : ""));
}
// } else {
// alert(title + (message ? "\n" + message : ""));
// }
}

//创建窗口
Expand Down Expand Up @@ -367,7 +367,7 @@ chrome.browserAction.onClicked.addListener(function (tab) {
if (chromeVersion < 45 && firefoxVersion < (isMobile ? 55 : 48)) {
notice(chrome.i18n.getMessage("extVersion"));
} else {
if (!isMobile) {
// if (!isMobile) {
if (scoreTabId) {
if (runningWindowId) {
chrome.windows.update(runningWindowId, { "focused": true, "state": "normal" });
Expand All @@ -384,21 +384,21 @@ chrome.browserAction.onClicked.addListener(function (tab) {
scoreTabId = window.tabs[window.tabs.length - 1].id;
});
}
} else {
if (scoreTabId) {
if (runningTabId) {
chrome.tabs.update(runningTabId, { "active": true });
} else {
chrome.tabs.update(scoreTabId, { "active": true });
}
} else {
channelUrls = {};
chooseLogin = 0;
chrome.tabs.create({ "url": urlMap.points }, function (tab) {
scoreTabId = tab.id;
});
}
}
// } else {
// if (scoreTabId) {
// if (runningTabId) {
// chrome.tabs.update(runningTabId, { "active": true });
// } else {
// chrome.tabs.update(scoreTabId, { "active": true });
// }
// } else {
// channelUrls = {};
// chooseLogin = 0;
// chrome.tabs.create({ "url": urlMap.points }, function (tab) {
// scoreTabId = tab.id;
// });
// }
// }
}
});

Expand All @@ -412,7 +412,7 @@ chrome.tabs.onRemoved.addListener(function (tabId, removeInfo) {
});

//窗口移除事件
if (!isMobile) {
// if (!isMobile) {
chrome.windows.onRemoved.addListener(function (windowId) {
if (windowId === runningWindowId) {
runningWindowId = 0;
Expand All @@ -421,7 +421,7 @@ if (!isMobile) {
chrome.browserAction.setBadgeText({ "text": "" });
}
});
}
// }

//通信事件
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
Expand All @@ -435,7 +435,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
break;
case "startRun":
if (!Object.keys(channelUrls).length) {
if (!isMobile) {
// if (!isMobile) {
if (!runningWindowId) {
getPointsData(function (data) {
if (userId !== data.userId) {
Expand Down Expand Up @@ -463,34 +463,34 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
});
});
}
} else {
if (!runningTabId) {
getPointsData(function (data) {
if (userId !== data.userId) {
usedUrls = {
"article": [],
"video": []
}
}
userId = data.userId;
chrome.tabs.create({ "url": urlMap.index }, function (tab) {
runningTabId = tab.id;
setTimeout(function () {
channelUrls["exam-practice"] = urlMap.dailyAsk;
channelUrls["exam-weekly"] = urlMap.weeklyAsk;
channelUrls["exam-paper"] = urlMap.paperAsk;
getChannelData("article", function (list) {
channelUrls["article"] = list;
getChannelData("video", function (list) {
channelUrls["video"] = list;
autoEarnPoints(1000 + Math.floor(Math.random() * 1000));
});
});
}, 1000 + Math.floor(Math.random() * 3000));
});
});
}
}
// } else {
// if (!runningTabId) {
// getPointsData(function (data) {
// if (userId !== data.userId) {
// usedUrls = {
// "article": [],
// "video": []
// }
// }
// userId = data.userId;
// chrome.tabs.create({ "url": urlMap.index }, function (tab) {
// runningTabId = tab.id;
// setTimeout(function () {
// channelUrls["exam-practice"] = urlMap.dailyAsk;
// channelUrls["exam-weekly"] = urlMap.weeklyAsk;
// channelUrls["exam-paper"] = urlMap.paperAsk;
// getChannelData("article", function (list) {
// channelUrls["article"] = list;
// getChannelData("video", function (list) {
// channelUrls["video"] = list;
// autoEarnPoints(1000 + Math.floor(Math.random() * 1000));
// });
// });
// }, 1000 + Math.floor(Math.random() * 3000));
// });
// });
// }
// }
}
break;
case "useUrl":
Expand Down
52 changes: 30 additions & 22 deletions js/exampaper.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
function getNeedAnswer() {
var isNextPage = true;
document.querySelectorAll('.item .right > button').forEach(function (e, b, c) {
if (isNextPage) {
let i = e.innerText;
if (i != "" && (i == '开始答题' || i == '继续答题')) {
isNextPage = false;
e.click();
return;
}
}
});
chrome.runtime.sendMessage({"method": "checkTab"}, {}, function (response) {
if (response && response.hasOwnProperty("runtime")) {
if (response.runtime) {
window.onload = function (){
function getNeedAnswer() {
var isNextPage = true;
document.querySelectorAll('.item .right > button').forEach(function (e, b, c) {
if (isNextPage) {
let i = e.innerText;
if (i != "" && (i == '开始答题' || i == '继续答题')) {
isNextPage = false;
e.click();
return;
}
}
});

if (isNextPage) {

if (isNextPage) {
var li = document.getElementsByClassName("ant-pagination-next")[0];
if (li.getAttribute("aria-disabled") == "false") {
document.querySelector('a.ant-pagination-item-link > i.anticon-right').click();
setTimeout(getNeedAnswer, parseInt(1000));
} else {
chrome.runtime.sendMessage({"method": "paperTitle"});
}
}
}

var li = document.getElementsByClassName("ant-pagination-next")[0];
if (li.getAttribute("aria-disabled") == "false") {
document.querySelector('a.ant-pagination-item-link > i.anticon-right').click();
setTimeout(getNeedAnswer, parseInt(Math.random() * 1000));
} else {
chrome.runtime.sendMessage({ "method": "paperTitle" });
setTimeout(getNeedAnswer, parseInt(1000));
}
}
}
}

setTimeout(getNeedAnswer, parseInt(Math.random() * 1000));
});
Loading

0 comments on commit 172e74e

Please sign in to comment.