UESTC积极分子

UESTC积极分子学习平台刷课工具

当前为 2023-05-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name UESTC积极分子
  3. // @version 0.0.7
  4. // @description UESTC积极分子学习平台刷课工具
  5. // @author 4ehex + fang
  6. // @match https://dxpx.uestc.edu.cn/jjfz/*
  7. // @match https://dxpx.uestc.edu.cn/exam/*
  8. // @connect easylearn.baidu.com
  9. // @grant unsafeWindow
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @grant GM_registerMenuCommand
  14. // @grant GM_xmlhttpRequest
  15. // @require https://cdn.bootcdn.net/ajax/libs/jquery/2.0.0/jquery.js
  16. // @icon http://www.gov.cn/ztzl/17da/183d03632724084a01bb02.jpg
  17. // @license MIT
  18.  
  19. // @namespace https://greasyfork.org/zh-CN/users/1073349
  20. // ==/UserScript==
  21.  
  22. /* globals jQuery, $, waitForKeyElements */
  23.  
  24. let _self = unsafeWindow, url = location.pathname, videoLists = [], interval_id = -1;
  25.  
  26. //注册油猴菜单
  27. let id_course = RegisterTipMenu("course", "开/关 自动进入未完成课程", "自动进入未完成课程</p><p>(此功能将在进入课程中心时自动查找未完成必读课件的课程)</p>");
  28. let id_compulsory = RegisterTipMenu("compulsory", "开/关 自动进入必修课程", "自动进入必修课程</p><p>(此功能将在进入课程时自动查找未完成的必修课程)</p>");
  29. let id_back = RegisterTipMenu("back", "开/关 自动返回上一级", "自动返回上一级</p><p>(此功能将在完成视频列表里所有播放时, 返回上一级自动查找还未看的视频)</p>");
  30. let id_rightmenu = RegisterTipMenu("rightmenu", "开/关 右键菜单复制", "右键菜单复制</p><p>(此功能将开启右键菜单和复制)</p>");
  31. let id_answer = RegisterTipMenu("answer", "开/关 考试自动搜索答案", "自动搜索答案</p><p>(此功能将自动读取题目,通过百度题库搜索并显示答案)</p>")
  32. let id_about = GM_registerMenuCommand ("关于", function(){
  33. video_note();
  34. });
  35.  
  36.  
  37. //通过'百度教育'搜索答案
  38. if (url == "/jjfz/lesson/exam" && GM_getValue("answer")) {
  39. //↓添加一个搜索答案的浮窗
  40. //添加样式
  41. GM_addStyle("body {background: #e9e9e9;font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}.bd_answer {background: #ffffff;position:absolute;box-shadow: 3px 3px 2px grey;}.bd_answer header {background: #bd6982;padding: 10px 15px;color: #ffffff;font-size: 14px;cursor: move;}.bd_answer header:before, .bd_answer header:after {display: block;content: '';clear: both;}.bd_answer header h2, .bd_answer .body ul li .content h3 {margin: 0;padding: 0;font-size: 14px;float: left;}.bd_answer header h2 a {color: #ffffff;text-decoration: none;}.bd_answer header .tools {list-style: none;margin: 0;padding: 0;float: right;}.bd_answer header .tools li {display: inline-block;margin-right: 6px;}.bd_answer header .tools li:last-child {margin: 0;}.bd_answer header .tools li a {color: #ffffff;text-decoration: none;-webkit-transition: all 0.3s linear 0s;-moz-transition: all 0.3s linear 0s;-ms-transition: all 0.3s linear 0s;-o-transition: all 0.3s linear 0s;transition: all 0.3s linear 0s;}.bd_answer .body {position: relative;max-height: 360px;overflow-y: scroll;overflow-x: hidden;}.bd_answer .body .search {display: none;width: 100%;}.bd_answer .body .search.opened {display: block;}.bd_answer .body .search input {width: 100%;margin: 0;padding: 10px 15px;border: none;-webkti-box-size: border-box;-moz-box-size: border-box;box-size: border-box;}.bd_answer .body ul {list-style: none;padding: 0;margin: 0;border-top: 1px solid #f2f2f2;}.bd_answer .body ul li {position: relative;background: #ffffff;display: block;width: 100%;padding: 10px;box-sizing: border-box;}.bd_answer .body ul li:before, .bd_answer .body ul li:after {display: block;content: '';clear: both;}.bd_answer .body ul li:hover .thumbnail {background: #bd6982;}.bd_answer .body ul li:nth-child(2n) {background: #f2f2f2;}.bd_answer .body ul li .thumbnail {display: inline-block;background: #bfbfbf;width: 50px;color: #ffffff;line-height: 50px;text-align: center;text-decoration: none;-webkit-transition: background 0.3s linear 0s;-moz-transition: background 0.3s linear 0s;-ms-transition: background 0.3s linear 0s;-o-transition: background 0.3s linear 0s;transition: background 0.3s linear 0s;}.bd_answer .body ul li .thumbnail img {width: 100%;}.bd_answer .body ul li .content {display: inline-block;margin-left: 6px;vertical-align: top;line-height: 1;}.bd_answer .body ul li .content h3 {display: block;width: 100%;margin-bottom: 5px;color: #808080;}.bd_answer .body ul li .content .preview {display: block;width: 100%;max-width: 200px;margin-bottom: 5px;color: #cccccc;font-size: 12px;}.bd_answer .body ul li .content .meta {color: #b3b3b3;font-size: 12px;}.bd_answer .body ul li .content .meta a {color: #999999;text-decoration: none;}.bd_answer .body ul li .content .meta a:hover {text-decoration: underline;}.bd_answer .body ul li .message {display: none;position: absolute;top: 0;left: 0;overflow: hidden;height: 100%;width: 100%;padding: 10px;box-sizing: border-box;}.bd_answer footer a {background: #bd6982;display: block;width: 100%;padding: 10px 15px;color: #ffffff;font-size: 14px;text-align: center;text-decoration: none;box-sizing: border-box;}.bd_answer footer a:hover {background: #cd8ca0;-webkit-transition: background 0.3s linear 0s;-moz-transition: background 0.3s linear 0s;-ms-transition: background 0.3s linear 0s;-o-transition: background 0.3s linear 0s;transition: background 0.3s linear 0s;}.info {width: 300px;margin: 25px auto;text-align: center;}.info h1 {margin: 0;padding: 0;font-size: 20px;font-weight: 400;color: #333333;}.info span {color: #666666;font-size: 12px;}.info span a {color: #000000;text-decoration: none;}.info span .fa {color: #bd6982;}.info span .spoilers {color: #999999;margin-top: 5px;font-size: 10px;}");
  42. //添加html
  43. $("body").prepend(`<div class="bd_answer" id="asr1" style="width:auto;inset:107px auto auto 124.82px;height:auto;z-index: 9999999;"><header><h2 id="main_title" class="drag_zone">点击右侧获取答案👉</h2><ul class="tools" style="cursor:pointer"><li><div id="get_answer">◼</div></li><li><div id="clear_asr">🗑︎</div></li><li><div id="search_setting">⚙</div></li></ul></header><div class="body"><div><input id="search_num" placeholder="搜索数量(0-10)(默认为3)" type="number" min="1" max="10" style="width:98%"></div><ul id="info_container"><li><a class="thumbnail"style="width: 50px;word-wrap: break-word;word-break: break-all;" href="#">[简答]</a><div class="content"><h3>[题目]</h3><span class="preview">[答案]</span> <span class="meta"><a target="_blank" href="[#]">原网页链接</a></span></div></li></ul></div><footer class="drag_zone"><a style="cursor:move">拖动这里移动窗口</a></footer></div>`);
  44. //以下为针对新添加浮窗的JS脚本
  45. var _move=false;//移动标记
  46. var _x,_y;//鼠标离控件左上角的相对位置
  47. $(".drag_zone").click(function(){}).mousedown(function(e){
  48. _move=true;
  49. _x=e.pageX-parseInt($("#asr1").css("left"));
  50. _y=e.pageY-parseInt($("#asr1").css("top"));
  51. $(".bd_answer").fadeTo(20, 0.25);//点击后开始拖动并透明显示
  52. });
  53. $(document).mousemove(function(e){
  54. if(_move){
  55. var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
  56. var y=e.pageY-_y;
  57. $(".bd_answer").css({top:y,left:x});//控件新位置
  58. }
  59. }).mouseup(function(){
  60. _move=false;
  61. $(".bd_answer").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明
  62. });
  63. $("#clear_asr").click(function(){//清空答案
  64. $('#info_container').children().each(function(){$(this).remove()});
  65. });
  66. $("#search_setting").click(function(){
  67. if ($("#search_num").attr("style").indexOf("display: none") != -1) {
  68. $("#search_num").css('display', 'block');
  69. }
  70. else {
  71. $("#search_num").css('display', 'none');
  72. }
  73. });
  74. $("#get_answer").click(function(){
  75. let s_question = $(".exam_h2").text().substr($(".exam_h2").text().indexOf('.') + 1);//获取问题
  76. //console.log(s_question);
  77. $('#info_container').children().each(function(){$(this).remove()});//删除之前的元素
  78.  
  79. //拼接请求URL (pageSize代表返回几个搜索结果)
  80. let search_count = "3",
  81. search_url = "https://easylearn.baidu.com/edu-web/content/search?query=[question]&type=&page=1&pageSize=[seach_count]&clientType=pc",
  82. search_result_ids = new Array(),
  83. basicinfo_url = "https://easylearn.baidu.com/edu-web-go/shiti/basicinfo?id=[entityId]&eqid=&clientType=pc",//通过entityId获取问题答案
  84. basicinfo_result_iqa = new Map();//{id:[question, answer], ...}
  85.  
  86. if ($("#search_num").val() != '') search_count = $("#search_num").val();
  87. search_url = search_url.replace("[seach_count]", search_count);
  88.  
  89. //发送搜索题目的GET请求 同步方式
  90. $("#main_title").text('正在发送搜索问题GET请求...');
  91. let true_search_url = search_url.replace("[question]", encodeURIComponent(s_question));
  92. SyncXmlHttpRequest(true_search_url, "GET").then((res) => {
  93. let search_parse = $.parseJSON(res);
  94. if (search_parse.errmsg != "success") {
  95. console.log("[Error] Search GET response Json Not success!");
  96. return alert("搜索响应结果不是success!");
  97. }
  98.  
  99. if (search_parse.data.list.length <= 0) {
  100. console.log("[Error] Search GET response Json List Empty!");
  101. $("#main_title").text('搜索为空请手动去网页上搜...');
  102. return alert("搜索响应结果为空!");
  103. }
  104.  
  105. search_parse.data.list.forEach(function (item, index) {//遍历搜索结果的entityId
  106. if (item.entityId != null) search_result_ids.push(item.entityId);
  107. });
  108.  
  109. if (search_result_ids.length <= 0) {
  110. console.log("[Error] Search Result Empty!");
  111. return alert("搜索结果为空!");
  112. }
  113.  
  114. //发送获取答案的GET请求 同步方式
  115. var promises = search_result_ids.map(function (item) {
  116. //console.log("[Debug] id: " + item);
  117. let true_basicinfo_url = basicinfo_url.replace("[entityId]", item);
  118. return SyncXmlHttpRequest(true_basicinfo_url, "GET").then((res) => {
  119. let basicinfo_parse = $.parseJSON(res);
  120. if (basicinfo_parse.errmsg != "success") {
  121. console.log("[Error] BasicInfo GET response Json Not success!");
  122. return alert("获取答案响应结果不是success!");
  123. }
  124. basicinfo_result_iqa[basicinfo_parse.data.id] = [basicinfo_parse.data.strquestion, basicinfo_parse.data.answer[0].desc];
  125.  
  126. //console.log("[Debug] 题目: " + basicinfo_parse.data.strquestion);
  127. //console.log("[Debug] 解答: " + basicinfo_parse.data.answer[0].desc);
  128. }).catch((err) => {
  129. console.log("[Error] " + err);
  130. return alert(err);
  131. });
  132. });
  133. $("#main_title").text('题目搜索完毕,发送搜索答案GET请求...');
  134. Promise.all(promises).then(() => {//统一执行
  135. //添加元素到浮窗
  136. let template_li = `<li><a class="thumbnail"style="width: 50px; word-wrap: break-word;word-break: break-all;" href="#">[简答]</a><div class="content"><h3>[题目]</h3><span class="preview">[答案]</span> <span class="meta"><a target="_blank" href="[#]">原网页链接</a></span></div></li>`,
  137. org_answer_url = "https://easylearn.baidu.com/edu-page/tiangong/questiondetail?id=[entityId]&from=jySearch";
  138. $.each(basicinfo_result_iqa, function(key, value){
  139. //console.log("[Debug ]ID: "+ key + "题目: " + value[0] + "[答案]: " + value[1]);
  140. let str_tmp = template_li.replace("[题目]", value[0].substr(0, 20));
  141. if (value[1].indexOf("<img") != -1) {//答案中有图片
  142. let img_ = `<img style="width: auto; height: auto; max-width: 100%; max-height: 60%;"src=` + GetImgSrc(value[1])[0] + "/>";
  143. str_tmp = str_tmp.replace("[答案]", img_);
  144. str_tmp = str_tmp.replace("[简答]", "图片");
  145. }
  146. else {
  147. str_tmp = str_tmp.replace("[答案]", GetPlainText(value[1]));
  148. str_tmp = str_tmp.replace("[简答]", GetPlainText(value[1]).substr(0, 3));
  149. }
  150. str_tmp = str_tmp.replace("[#]", org_answer_url.replace("[entityId]", key));
  151.  
  152. $('#info_container').append(str_tmp);
  153. });
  154. $("#main_title").text('全部已完成...');
  155. });
  156. }).catch((err) => {
  157. console.log("[Error] " + err);
  158. return alert(err);
  159. });
  160. });
  161. }
  162.  
  163. if (GM_getValue("rightmenu")) openCopy();
  164.  
  165. //console.log("[Debug] " + url);
  166.  
  167. //定位到'必读课件'<'已完成必读课件'的课程 并自动跳转到'课程中心-精品课程'
  168. if (url == "/jjfz/lesson") {
  169. if (!GM_getValue("dont_note")) video_note();
  170.  
  171. if(interval_id!= -1) {
  172. clearInterval(interval_id);
  173. interval_id = -1;
  174. }
  175.  
  176. if (GM_getValue("course")) {
  177. let completed_count = 0, course_count = $(".lesson_c_ul").children().length;
  178.  
  179. $(".lesson_center_dl").each( function() {
  180. let courseware_ = $(this).text();
  181. let required_ = parseInt(courseware_.substr(courseware_.indexOf("必读课件:") + 5, 4));
  182. let completed_ = parseInt(courseware_.substr(courseware_.indexOf("已完成必读课件:") + 8), 4);
  183. //console.log("必读课件:" + required_ + "\n已完成:" + completed_);
  184. if (required_ > completed_) {//未完成
  185. $(this).next().children()[0].click();//点击'开始学习'
  186. return false;
  187. }
  188. else{
  189. completed_count += 1;
  190. if (completed_count >= course_count) {
  191. alert_note(2, ["好的", "关闭刷课功能"], "提示", '<p>已刷完全部课程</p><p>感谢使用!</p>', 'public_cont1', function () {
  192. $(".public_close").click();
  193. },function (){
  194. GM_setValue("course", false);GM_setValue("compulsory", false);GM_setValue("back", false);
  195. $(".public_close").click();
  196. alert("已关闭 [自动进入未完成课程] [自动进入必修课程] [自动返回上一级]");
  197. });
  198. return false;
  199. }
  200. }
  201. });
  202. }
  203. }
  204.  
  205. if (url == "/jjfz/lesson/video" && GM_getValue("compulsory")) {
  206. if(interval_id!= -1) {
  207. clearInterval(interval_id);
  208. interval_id = -1;
  209. }
  210.  
  211. //如果URL最后一位是#则删去
  212. if (window.location.href.substr(-1) == "#") {
  213. window.location.href = window.location.href.replace(/\#$/, '');
  214. return;
  215. }
  216.  
  217. //转到'必修'页面
  218. if (getUrlParam("required") == null || getUrlParam("required") != '1'){
  219. UpdateUrlParam("required", 1);
  220. return;
  221. }
  222.  
  223. let page_count = 1, page_cur = 1, lesson_cur = 0, completed_cur = 0;
  224. //获取有几页课程 (判断.page_btn是否存在)
  225. if ($(".page_btn").length != 0) {
  226. page_count = $(".page_btn").siblings("a").length - 2;//a标签还有page_go和末页
  227. page_cur = parseInt($(".page_btn").text());
  228. }
  229.  
  230. lesson_cur = $(".lesson1_lists ul:first").children().length;
  231.  
  232. //定位到未完成课程 并自动进入
  233. $(".lesson1_lists ul:first").children().each( function() {
  234. if ($(this).find(".lesson_pass").length == 0) {//判断是否有"完成"标志 没有则进入
  235. $(this).children()[0].click();
  236. return false;
  237. }
  238. else {
  239. completed_cur += 1;
  240. if (completed_cur >= lesson_cur) {//如果已完成的课程等于列表课程数 则翻页 如果到末页则返回上一级
  241. if (page_cur >= page_count) {
  242. console.log("全部已完成,返回课程中心");
  243. if (GM_getValue("back")) $(".head_top_left").find(".head_cut")[0].click();
  244. }
  245. else{
  246. UpdateUrlParam("page", page_cur + 1);
  247. return false;
  248. }
  249. }
  250. }
  251. });
  252.  
  253. }
  254.  
  255. if (url.indexOf("jjfz/play") != -1) {
  256. getVideoList();//获取视频播放列表
  257.  
  258. let nextVideoFlag = false,
  259. nextClassFlag = false;
  260.  
  261. //不加muted谷歌不让自动播放
  262. setVideoMuted();
  263.  
  264. interval_id = setInterval(() => {
  265. nextVideoFlag = closeAlert();
  266. nextClassFlag = jumpToVideo(videoLists);
  267. if (nextVideoFlag) nextClassFlag = nextVideo(videoLists);
  268. if (nextClassFlag) goBack();
  269. }, 1000)
  270. }
  271.  
  272. function getVideoList() {
  273. if ($(".video_lists li").length) {
  274. //console.log("当前视频" + $(".video_red1").text())
  275. videoLists = $(".video_lists li");
  276. }
  277. }
  278.  
  279. function closeAlert(){
  280. if($(".video_red1>a").css("color") == "rgb(255, 0, 0)"){
  281. nextVideo();
  282. }else if($(".public_cont>.public_text>p").text().indexOf('您需要完整观看一遍课程视频') != -1){
  283. $(".public_cont>.public_btn>a")[0].click();
  284. }else if($(".public_cont>.public_text>p").text().indexOf('视频已暂停') != -1){
  285. $(".public_cont>.public_btn>a")[0].click();
  286. }else if($(".public_btn>.public_cancel").text().indexOf('继续观看') != -1 ) {
  287. $(".public_btn>.public_cancel")[0].click();
  288. }else if($(".public_cont>.public_text>p").text().indexOf('当前视频播放完毕') != -1){
  289. $(".public_cont>.public_btn>a")[0].click();
  290. }else if($(".public_cont>.public_text>p").text().indexOf('上次观看') != -1){
  291. $(".public_cont>.public_btn>a")[1].click();
  292. }else if($("#wrapper>div>div>button").attr("aria-label") == 'Play'){
  293. $("#wrapper>div>button").click();
  294. }
  295. }
  296.  
  297. //判断是否播放完毕过
  298. function isPlayOverEver() {
  299. //通过判断Player中是否有进度条来判断是否播放完毕
  300. if ($(".plyr__progress").length) {
  301. return true;
  302. }
  303. else {
  304. return false;
  305. }
  306. }
  307.  
  308. function nextVideo(){
  309. let videoCount = $(".video_lists>ul>li").length;
  310. $(".video_lists>ul>li").each((_,element) => {
  311. if($(element).children("a").css("color") != "rgb(255, 0, 0)"){//通过文本颜色判断是否播放完毕过 (红色为播放完毕过)
  312. $(element).children("a")[0].click()
  313. return false
  314. }else{
  315. videoCount--
  316. if(videoCount == 0) {
  317. console.log("列表播放完毕,返回课程页");
  318. clearInterval(interval_id);
  319. goBack();
  320. }
  321. }
  322. })
  323. }
  324.  
  325. function jumpToVideo(videoList) {
  326. if ($(".video_red1").find("a").attr("style") == "width:70%;color:red") {
  327. let index = $(videoList).index($(".video_red1"));
  328. if (videoList[index + 1]) {
  329. $(videoList[index + 1]).children("a").attr('id', 'aRemoveAllTxt');
  330. document.getElementById("aRemoveAllTxt").click();
  331. } else {
  332. return true;
  333. }
  334. }
  335. }
  336.  
  337. function goBack() {
  338. if (GM_getValue("back")) $('.video_goback')[0].click();
  339. }
  340.  
  341. //给player加上muted标签
  342. function setVideoMuted() {
  343. $(".video_play1").attr("muted");
  344. }
  345.  
  346. function openCopy() {
  347. $(document).ready(new function () {
  348. document.oncontextmenu = new Function("event.returnValue=true");
  349. document.onselectstart = new Function("event.returnValue=true");
  350. document.oncopy = new Function("return true");
  351. })
  352. }
  353.  
  354. function video_note() {
  355. alert_note(2, ["关闭", "不再提示"], "UESTC积极分子脚本使用说明", '<p>修改自YNU积极分子</p><p>(我没有学过前端 语法都是现查的 可能有BUG)</p>' +
  356. '<p><font color="aqua"></font>默认功能全关 可点击油猴图标进行设置</p>' +
  357. '<p>本脚本免费使用严谨倒卖</p>',
  358. 'public_cont1', function () {
  359. $(".public_close").click(); //此为关闭方法
  360. GM_setValue("dont_note", false)
  361. }, function () {
  362. $(".public_close").click(); //此为关闭方法
  363. GM_setValue("dont_note", true)
  364. });
  365. }
  366.  
  367. function alert_note(btn_num, btn_text, note_text, public_text, public_cont_class, submit_fun, cancel_fun) {
  368. var public_a;
  369. if (btn_num == 1) {
  370. public_a = '<a href="#" class="public_submit">' + btn_text[0] + '</a>';
  371. } else {
  372. public_a = '<a href="#" class="public_submit">' + btn_text[0] + '</a> <a href="#" class="public_cancel">' + btn_text[1] + '</a>';
  373. }
  374. var public_html = '<div class="public_mask"></div><div class="public_cont ' + public_cont_class + '"><div class="public_title"><h3>' + note_text + '</h3><div class="public_close"></div></div><div class="public_text">' + public_text + '</div><div class="public_btn">' + public_a + '</div></div>';
  375. $("body").append(public_html);
  376. $(".public_close").click(function () {
  377. $(".public_mask").remove();
  378. $(".public_cont").remove();
  379. });
  380. $(".public_mask").click(function () {
  381. $(".public_mask").remove();
  382. $(".public_cont").remove();
  383. });
  384. if (btn_num == 1) {
  385. $(".public_submit").click(function () {
  386. submit_fun();
  387. })
  388. } else {
  389. $(".public_submit").click(function () {
  390. submit_fun();
  391. });
  392. $(".public_cancel").click(function () {
  393. cancel_fun();
  394. })
  395. }
  396. }
  397.  
  398. // 获取url中参数的值
  399. function getUrlParam(name) {
  400. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
  401. var r = window.location.search.substr(1).match(reg);
  402. if (r!=null) return (r[2]); return null;
  403. }
  404.  
  405. // 添加 修改 url中参数的值
  406. function UpdateUrlParam(name, val) {
  407. let thisURL = document.location.href;
  408.  
  409. // 如果 url中包含这个参数 则修改
  410. if (thisURL.indexOf(name+'=') > 0) {
  411. let v = getUrlParam(name);
  412. if (v != null) {// 是否包含参数
  413. thisURL = thisURL.replace(name + '=' + v, name + '=' + val);
  414. }
  415. else {
  416. thisURL = thisURL.replace(name + '=', name + '=' + val);
  417. }
  418. }
  419. else {// 不包含这个参数 则添加
  420. if (thisURL.indexOf("?") > 0) {
  421. thisURL = thisURL + "&" + name + "=" + val;
  422. }
  423. else {
  424. thisURL = thisURL + "?" + name + "=" + val;
  425. }
  426. }
  427.  
  428. if (thisURL != document.location.href) document.location.href = thisURL;
  429. };
  430.  
  431. //注册油猴提示菜单
  432. function RegisterTipMenu(id, menu_text, tip_text) {
  433. let id_menu = GM_registerMenuCommand (menu_text, function(){
  434. if (GM_getValue(id)) {
  435. GM_setValue(id, false);
  436. alert_note(1, ["关闭"], "提示", '<p>已关闭 ' + tip_text, 'public_cont1', function () {
  437. $(".public_close").click();
  438. });
  439. }
  440. else {
  441. GM_setValue(id, true);
  442. alert_note(1, ["关闭"], "提示", '<p>已开启 ' + tip_text, 'public_cont1', function () {
  443. $(".public_close").click();
  444. });
  445. }
  446. });
  447. }
  448.  
  449. //以同步方式发送跨域请求
  450. function SyncXmlHttpRequest(request_url, method_type) {
  451. return new Promise((resolve, reject) => {
  452. GM_xmlhttpRequest({
  453. method: method_type,
  454. url: request_url,
  455. headers: {
  456. "Accept": "application/json, text/plain, */*",
  457. "Accept-Encoding": "gzip, deflate, br",
  458. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"
  459. },
  460. onload: function(response) {
  461. if (response.status != 200){
  462. return reject("Search GET response Not 200 OK!");
  463. }
  464. //console.log("[Debug] " + response.responseText);
  465. return resolve(response.responseText);
  466. },
  467. onerror: function(err) {
  468. return reject(err);
  469. }
  470. });
  471. });
  472. }
  473.  
  474. //去除文本中的html标签
  475. function GetPlainText(val) {
  476. if (val != null && val != "") {
  477. var re1 = new RegExp("<.+?>|&.+?;","g"); //匹配html标签的正则表达式,"g"是搜索匹配多个符合的内容
  478. var msg = val.replace(re1,""); //执行替换成空字符
  479. msg = msg.replace(/\s/g,""); //去掉所有的空格(中文空格、英文空格都会被替换)
  480. msg = msg.replace(/[\r\n]/g,""); //去掉所有的换行符
  481. return msg;
  482. } else return ''
  483. }
  484.  
  485. //获取<img>中的src的值
  486. function GetImgSrc(article) {
  487. let reg = /(< img|<img).*?(?:>|\/>)/gim //匹配所有图片标签
  488. let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i // 匹配图片中的src
  489. return article.match(reg).map(val => {
  490. let src = val.match(srcReg)
  491. return src[1]
  492. });
  493. }