简法主页功能增强

在简法主页上增加其他个性化设置

目前為 2021-10-19 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 简法主页功能增强
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.13
  5. // @description 在简法主页上增加其他个性化设置
  6. // @author 那年那兔那些事
  7. // @match https://www.jianfast.com
  8. // @match https://www.jianfast.com/?pc=1
  9. // @match https://www.jianfast.com/m
  10. // @icon https://s3.bmp.ovh/imgs/2021/08/2a5feb8f5f886e70.png
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. //添加window.onload方法,防止window.onload相互覆盖覆盖
  15. function addLoadEvent(newOnload) {
  16. var oldOnload = window.onload;
  17. if (typeof window.onload != 'function') {
  18. window.onload = newOnload;
  19. } else {
  20. window.onload = function() {
  21. oldOnload();
  22. newOnload();
  23. }
  24. }
  25. }
  26. //store为本地存储功能
  27. var store = {
  28. //set方法在localstorage中修改指定JSON数据
  29. set: function(key, val) {
  30. if (!val) {
  31. return;
  32. }
  33. try {
  34. var json = JSON.stringify(val);
  35. if (typeof JSON.parse(json) === "object") { // 验证一下是否为JSON字符串防止保存错误
  36. localStorage.setItem(key, json);
  37. }
  38. } catch (e) {
  39. return false;
  40. }
  41. },
  42. //get方法在localstorage中获取指定JSON数据
  43. get: function(key) {
  44. if (this.has(key)) {
  45. return JSON.parse(localStorage.getItem(key));
  46. }
  47. },
  48. //has方法在localstorage中查询指定JSON数据是否存在
  49. has: function(key) {
  50. if (localStorage.getItem(key)) {
  51. return true;
  52. } else {
  53. return false;
  54. }
  55. },
  56. //del方法在localstorage中删除指定JSON数据
  57. del: function(key) {
  58. localStorage.removeItem(key);
  59. }
  60. };
  61. //settings对象为设置项
  62. var settings = {
  63. settingsData: {
  64. searchEngine: true, //true:当前标签页打开搜索结果;false:新标签页打开搜索结果
  65. bookMarks: true, //true:当前标签页打开书签网页;false:新标签页打开书签网页
  66. settingsPurify: true, //true:开启设置页广告净化;false:关闭设置页广告净化
  67. hideRandBg: true, //true:开启主页随机背景入口隐藏;false:关闭主页随机背景入口隐藏
  68. serchForcast: true //true:开启搜索栏联想词预测;false:关闭搜索栏联想词预测
  69. },
  70. backupData: {}, //用于备份数据
  71. //get方法获取settings对象settingsData属性
  72. get: function(key) {
  73. return this.settingsData[key];
  74. },
  75. //get方法获取settings对象settingsData所有属性
  76. getAll: function() {
  77. return this.settingsData;
  78. },
  79. //getBackup方法获取settings对象backupData所有属性
  80. getBackup: function() {
  81. return this.backupData;
  82. },
  83. //set方法设置settings对象settingsData属性
  84. set: function(key, value) {
  85. if (typeof value === "boolean") {
  86. this.settingsData[key] = value;
  87. } else {
  88. console.log("value错误");
  89. }
  90. },
  91. //initData方法初始化settings对象属性
  92. initData: function() {
  93. this.backupData = this.settingsData;
  94. var localData = store.get("settingsData");
  95. var settingsData = this.settingsData;
  96. if (localData) {
  97. this.settingsData = {
  98. ...settingsData,
  99. ...localData
  100. };
  101. } else {
  102. store.set("settingsData", this.settingsData);
  103. }
  104. },
  105. //init方法初始化搜索引擎与书签的打开方式
  106. init: function() {
  107. this.initData();
  108. newSettingsPageFn.init();
  109. searchEngine.init();
  110. bookMarks.init();
  111. serchForcast.init();
  112. settingsPurify.init();
  113. hideRandBg.init();
  114. console.log("简法主页功能增强:初始化完成");
  115. },
  116. //monitor方法用于检错、监控修改结果
  117. monitor: function() {
  118. var Timer = setInterval(function() {
  119. searchEngine.monitor();
  120. bookMarks.monitor();
  121. serchForcast.monitor();
  122. settingsPurify.monitor();
  123. hideRandBg.monitor();
  124. }, 500);
  125. console.log("简法主页功能增强:检错程序启动(定时器ID:" + Timer + ")");
  126. },
  127. //on方法用于启动整个程序
  128. on: function() {
  129. console.log("简法主页功能增强:主程序启动");
  130. this.init();
  131. this.monitor();
  132. }
  133. }
  134. //newSettingsPageFn为增强设置页
  135. var newSettingsPageFn = {
  136. optData: [{
  137. tittle: "搜索结果打开方式",
  138. value: "searchEngine",
  139. choice: [{
  140. t: "当前标签页",
  141. v: true
  142. }, {
  143. t: "新标签页",
  144. v: false
  145. }]
  146. }, {
  147. tittle: "主页书签打开方式",
  148. value: "bookMarks",
  149. choice: [{
  150. t: "当前标签页",
  151. v: true
  152. }, {
  153. t: "新标签页",
  154. v: false
  155. }]
  156. }, {
  157. tittle: "搜索栏联想词预测",
  158. value: "serchForcast",
  159. choice: [{
  160. t: "开启预测",
  161. v: true
  162. }, {
  163. t: "关闭预测",
  164. v: false
  165. }]
  166. }, {
  167. tittle: "设置页广告净化",
  168. value: "settingsPurify",
  169. choice: [{
  170. t: "开启净化",
  171. v: true
  172. }, {
  173. t: "关闭净化",
  174. v: false
  175. }]
  176. }, {
  177. tittle: "随机背景入口隐藏",
  178. value: "hideRandBg",
  179. choice: [{
  180. t: "开启隐藏",
  181. v: true
  182. }, {
  183. t: "关闭隐藏",
  184. v: false
  185. }]
  186. }, {
  187. tittle: "关于脚本",
  188. type: "note",
  189. noteData: [{
  190. l: "当前版本",
  191. r: "Version0.13"
  192. }, {
  193. l: "版本更新",
  194. r: "<span id='updateBtn'>GreasyFork</span>"
  195. }, {
  196. l: "反馈建议",
  197. r: "<span id='contactBtn'>点此处反馈</span>"
  198. }, {
  199. l: "导入配置",
  200. r: "<span id='importSetBtn'>点此处导入</span>"
  201. }, {
  202. l: "导出配置",
  203. r: "<span id='exportSetBtn'>点此处导出</span>"
  204. }, {
  205. l: "重置配置",
  206. r: "<span id='recoverSetBtn'>点此处重置</span>"
  207. }]
  208. }],
  209. //clickFn方法为设置选项按钮的点击功能
  210. clickFn: function(id, key) {
  211. var Obj = document.getElementById(id);
  212. var setValue = settings.get(key);
  213. var optValue = Obj.value;
  214. if (setValue !== optValue) {
  215. settings.set(key, optValue);
  216. var newObj = Obj.parentElement.children;
  217. for (let i = 0; i < newObj.length; i++) {
  218. if (newObj[i].id === id) {
  219. newObj[i].style.border = "1px solid #2c7bf6";
  220. newObj[i].style.color = "#2c7bf6";
  221. } else {
  222. newObj[i].style.border = "1px solid rgba(0, 0, 0, 0.1)";
  223. newObj[i].style.color = "";
  224. }
  225. }
  226. saveFlag = true;
  227. var newSaveBox = document.getElementById("new-save-box");
  228. if (newSaveBox && newSaveBox.style.display === "none") {
  229. newSaveBox.style.display = "flex";
  230. }
  231. var tittleBox = document.getElementById("console-title-box");
  232. if (tittleBox && tittleBox.style.display !== "none") {
  233. tittleBox.style.display = "none";
  234. }
  235. }
  236. },
  237. //createTittle方法创建一个盛放设置标题的元素对象
  238. createTittle: function(val) {
  239. var Box = document.createElement("div");
  240. Box.setAttribute("class", "console-bigTitle");
  241. Box.innerText = val;
  242. return Box;
  243. },
  244. //createChoiceBtn方法创建一个设置选项按钮对象
  245. createChoiceBtn: function(choice, id) {
  246. var Btn = document.createElement("div");
  247. var BtnID = id + "-" + choice.v;
  248. var key = id.slice("moreSet-Opt-".length);
  249. Btn.style =
  250. "padding: 0 10px;width: 35%;margin: 5px 10px;height: 25px;box-sizing: border-box;line-height: 23px;text-align: center;border-radius: 100px;font-size: 13px;border: 1px solid rgba(0, 0, 0, 0.1);cursor: pointer;user-select: none;transition: all .3s;";
  251. Btn.innerText = choice.t;
  252. Btn.value = choice.v;
  253. Btn.id = BtnID;
  254. Btn.onclick = function() {
  255. newSettingsPageFn.clickFn(BtnID, key);
  256. };
  257. if (settings.get(key) === choice.v) {
  258. Btn.style.border = "1px solid #2c7bf6";
  259. Btn.style.color = "#2c7bf6";
  260. }
  261. return Btn;
  262. },
  263. //createChoice方法创建一个设置选项按钮对象的集合对象
  264. createChoice: function(value, choice) {
  265. var Box = document.createElement("div");
  266. var BoxID = "moreSet-Opt-" + value;
  267. Box.style =
  268. "width:100%;display:flex;justify-content:center;flex-flow:row wrap;margin-top:15px;";
  269. Box.id = BoxID
  270. var Btn;
  271. if (Array.isArray(choice)) {
  272. for (let i = 0; i < choice.length; i++) {
  273. Btn = this.createChoiceBtn(choice[i], BoxID);
  274. Box.appendChild(Btn);
  275. }
  276. } else {
  277. Btn = this.createChoiceBtn(choice, BoxID);
  278. Box.appendChild(Btn);
  279. }
  280. return Box;
  281. },
  282. //createOpt方法创建一个完整的设置项对象
  283. createOpt: function(tittle, value, choice) {
  284. var ResObj = false;
  285. if (tittle && value && choice) {
  286. ResObj = document.createElement("div");
  287. var newTittle = this.createTittle(tittle);
  288. var newChoice = this.createChoice(value, choice);
  289. ResObj.appendChild(newTittle);
  290. ResObj.appendChild(newChoice);
  291. }
  292. return ResObj;
  293. },
  294. createNoteText: function(data) {
  295. var textObj = document.createElement("div");
  296. textObj.style = "width:100%;margin:5px;";
  297. textObj.innerHTML = "<span>" + data.l + "</span>";
  298. if (data.r) {
  299. textObj.innerHTML += "<span> : </span><span style='color:black'>" + data.r + "</span>";
  300. }
  301. return textObj;
  302. },
  303. createNoteData: function(noteData) {
  304. var newNoteBox = document.createElement("div");
  305. newNoteBox.style =
  306. "width: 60%;margin:20%;margin-top: 20px; text-align: center; line-height: 23px;";
  307. var newNoteText;
  308. if (Array.isArray(noteData)) {
  309. for (let i = 0; i < noteData.length; i++) {
  310. newNoteText = this.createNoteText(noteData[i]);
  311. newNoteBox.appendChild(newNoteText);
  312. }
  313. } else {
  314. newNoteText = this.createNoteText(noteData);
  315. newNoteBox.appendChild(newNoteText);
  316. }
  317. return newNoteBox;
  318. },
  319. //createNote方法创建一个文字性的提示对象
  320. createNote: function(tittle, noteData) {
  321. var ResObj = false;
  322. if (tittle && noteData) {
  323. ResObj = document.createElement("div");
  324. var newTittle = this.createTittle(tittle);
  325. var newNote = this.createNoteData(noteData);
  326. ResObj.appendChild(newTittle);
  327. ResObj.appendChild(newNote);
  328. }
  329. return ResObj;
  330. },
  331. //createPage方法创建一个增强设置页
  332. createPage: function(val) {
  333. var settingBox = document.createElement("div");
  334. settingBox.id = "console-moreSet-content";
  335. settingBox.style =
  336. "width: 100%;height: 100px;flex-grow: 1;overflow: auto;box-sizing: border-box;padding: 0 25px 0 0;margin: 10px 0;display: none";
  337. var newOpt;
  338. for (let i = 0; i < val.length; i++) {
  339. if (val[i].type) {
  340. if (val[i].type === "note") {
  341. newOpt = this.createNote(val[i].tittle, val[i].noteData);
  342. settingBox.appendChild(newOpt);
  343. }
  344. } else {
  345. newOpt = this.createOpt(val[i].tittle, val[i].value, val[i].choice);
  346. settingBox.appendChild(newOpt);
  347. }
  348. }
  349. document.getElementById("console-box").appendChild(settingBox);
  350. },
  351. //createMenu方法在设置菜单中创建增强设置功能入口
  352. createMenu: function() {
  353. var menuBtn = document.createElement("div");
  354. menuBtn.setAttribute("class", "console-menu-btn");
  355. menuBtn.id = "moreSetBtn";
  356. menuBtn.innerText = "增强设置";
  357. menuBtn.onclick = this.on;
  358. document.getElementById("console-menu-main").appendChild(menuBtn);
  359. },
  360. //createSaveBtn方法创建一个保存按钮对象
  361. createSaveBtn: function() {
  362. var oldSaveBox = document.getElementById("save-box");
  363. var newSaveBox = document.createElement("div");
  364. newSaveBox.style.display = "none";
  365. newSaveBox.id = "new-save-box";
  366. var newSaveBtn = document.createElement("div");
  367. newSaveBtn.style =
  368. "font-size: 14px;display: flex;justify-content: center;align-items: center;background-color: #4486f6;color: white;height: 25px;width: 120px;border-radius: 100px;margin-right: 10px;cursor: pointer;";
  369. var newSaveIcon = document.createElement("img");
  370. newSaveIcon.style = "width: 13px;height: 13px;margin-right: 5px;";
  371. newSaveIcon.setAttribute("src", "/static/home/images/console/saveicon.svg");
  372. var newSaveTittle = document.createElement("span");
  373. newSaveTittle.innerText = "保存并应用";
  374. newSaveBtn.onclick = function() {
  375. if (saveFlag) {
  376. store.set("settingsData", settings.getAll());
  377. saveFlag = false;
  378. console.log("保存增强设置");
  379. setTimeout(function() {
  380. var msgBox = document.getElementById("msg-box");
  381. msgBox.style =
  382. "opacity:0.8;margin-top:50px;display:inline-block;";
  383. msgBox.innerText = "增强设置保存成功";
  384. setTimeout(function() {
  385. location.reload();
  386. }, 500);
  387. }, 300);
  388. }
  389. document.getElementById("console-close-btn").click();
  390. };
  391. newSaveBtn.appendChild(newSaveIcon);
  392. newSaveBtn.appendChild(newSaveTittle);
  393. newSaveBox.appendChild(newSaveBtn);
  394. oldSaveBox.parentElement.insertBefore(newSaveBox, oldSaveBox);
  395. },
  396. //on方法是增强设置页面的启动方法
  397. on: function() {
  398. var moreSetPage = document.getElementById("console-moreSet-content");
  399. if (moreSetPage) {
  400. document.getElementsByClassName("console-title-img")[0].src =
  401. "/static/home/images/console/set1.svg";
  402. document.getElementsByClassName("console-title")[0].innerText = "增强设置";
  403. document.getElementById("console-menu").style.display = "none";
  404. moreSetPage.style.display = "block";
  405. } else {
  406. console.log("增强设置页不存在");
  407. }
  408. },
  409. //off方法是增强设置页面的关闭/隐藏方法
  410. off: function() {
  411. var moreSetPage = document.getElementById("console-moreSet-content");
  412. var newSaveBox = document.getElementById("new-save-box");
  413. if (moreSetPage && moreSetPage.style.display !== "none") {
  414. moreSetPage.style.display = "none";
  415. }
  416. if (newSaveBox.style.display !== "none") {
  417. newSaveBox.style.display = "none";
  418. }
  419. },
  420. //addExtEvent方法用于增加一些额外的事件
  421. addExtEvent: function() {
  422. var target;
  423. //版本更新
  424. target = document.getElementById("updateBtn");
  425. if (target) {
  426. target.onclick = function() {
  427. location.href = "https://gf.qytechs.cn/zh-CN/scripts/431279";
  428. }
  429. target.style.cursor = "pointer";
  430. }
  431. //反馈建议
  432. target = document.getElementById("contactBtn");
  433. if (target) {
  434. target.onclick = function() {
  435. location.href = "https://gf.qytechs.cn/zh-CN/scripts/431279/feedback";
  436. }
  437. target.style.cursor = "pointer";
  438. }
  439. //导入配置
  440. target = document.getElementById("importSetBtn");
  441. if (target) {
  442. target.onclick = function() {
  443. var data = prompt("在这粘贴需要导入的配置数据:");
  444. data = data.trim();
  445. try {
  446. if (data !== null && data !== "") {
  447. data = JSON.parse(data);
  448. store.set("settingsData", data.settingsData);
  449. alert("导入配置成功");
  450. location.reload();
  451. }
  452. } catch (e) {
  453. alert("配置数据错误,导入配置失败");
  454. }
  455. }
  456. target.style.cursor = "pointer";
  457. }
  458. //导出配置
  459. target = document.getElementById("exportSetBtn");
  460. if (target) {
  461. target.onclick = function() {
  462. var exportBox = document.createElement("input");
  463. exportBox.value = "{'settingsData':" + JSON.stringify(settings.getAll()) + "}";
  464. document.body.appendChild(exportBox);
  465. exportBox.select();
  466. document.execCommand('copy');
  467. exportBox.remove();
  468. alert("配置数据已成功导出到剪贴板");
  469. }
  470. target.style.cursor = "pointer";
  471. }
  472. //重置配置
  473. target = document.getElementById("recoverSetBtn");
  474. if (target) {
  475. target.onclick = function() {
  476. var msg = "即将重置配置数据\n点击确认开始重置";
  477. if (confirm(msg)) {
  478. var data = settings.getBackup();
  479. if (JSON.stringify(data).trim() !== "{}") {
  480. store.set("settingsData", data);
  481. alert("配置数据重置成功");
  482. location.reload();
  483. } else {
  484. msg = "重置配置功能错误,请联系脚本制作者\n点击确认前往反馈";
  485. if (confirm(msg)) {
  486. var btn = document.getElementById("contactBtn");
  487. if (btn) {
  488. btn.click();
  489. }
  490. }
  491. }
  492. }
  493. }
  494. target.style.cursor = "pointer";
  495. }
  496. },
  497. //initPC方法是针对PC模式的增强设置初始化方法,是增强设置的启动方法
  498. initPC: function() {
  499. var consoleBox = document.getElementById("console-box");
  500. if (consoleBox) {
  501. var closeBtn = document.getElementById("console-close-btn");
  502. if (closeBtn) {
  503. closeBtn.addEventListener("click", newSettingsPageFn.off);
  504. }
  505. this.createMenu();
  506. this.createSaveBtn();
  507. this.createPage(this.optData);
  508. this.addExtEvent();
  509. }
  510. },
  511. //initMobile方法是针对Mobile模式的增强设置初始化方法,是增强设置的启动方法
  512. initMobile: function() {
  513. var menuWrap = document.getElementById("menu-wrap");
  514. if (menuWrap) {
  515. var menuObj = menuWrap.children[1];
  516. if (menuObj && menuObj.tagName === "UL") {
  517. var newOpt = document.createElement("li");
  518. newOpt.style = "cursor:pointer;"
  519. newOpt.innerHTML = "<img src='/static/home/images/console/set1.svg'/><span>增强设置</span>";
  520. newOpt.onclick = function() {
  521. var res = confirm("增强设置请前往电脑版操作,点击确认前往电脑版");
  522. if (res) {
  523. location.href = "https://www.jianfast.com/?pc=1";
  524. }
  525. }
  526. menuObj.appendChild(newOpt);
  527. }
  528. var menuNotice = document.getElementById("menu-notice");
  529. var newNotice = "<div>" + menuNotice.children[1].innerText +
  530. "</div><div>对增强设置进行修改请前往电脑版网页操作</div><div>增强设置-搜索结果打开方式仅对电脑版生效</div>";
  531. menuNotice.children[1].innerHTML = newNotice;
  532. }
  533. },
  534. //init方法调用initPC方法与initMobile方法初始化增强设置,是对外统一调用的初始化方法
  535. init: function() {
  536. this.initPC();
  537. this.initMobile();
  538. }
  539. };
  540. //searchEngine对象为搜索引擎项
  541. var searchEngine = {
  542. //change方法用于改变搜索按钮类型,从而便于覆盖搜索打开方式
  543. change: function() {
  544. var searchBtn = document.getElementById("search-btn");
  545. if (searchBtn) {
  546. searchBtn.type = "text";
  547. }
  548. },
  549. //click方法用于覆盖原搜索按钮点击方法
  550. click: function() {
  551. if (location.href.search("jianfast.com/m") === -1) {
  552. var searchBar = document.getElementById("search");
  553. var url = searchBar.getAttribute("data-engine-start");
  554. var val = searchBar.value;
  555. if (settings.get("searchEngine")) {
  556. location.href = url + val;
  557. } else {
  558. open(url + val);
  559. }
  560. }
  561. },
  562. //enter方法用于覆盖原回车搜索方法
  563. enter: function(event) {
  564. if (event.keyCode === 13) {
  565. searchEngine.click();
  566. }
  567. },
  568. //init方法用于初始化搜索引擎,覆盖新方法
  569. init: function() {
  570. searchEngine.change();
  571. var searchBtn = document.getElementById("search-btn");
  572. if (searchBtn) {
  573. searchBtn.onclick = this.click;
  574. }
  575. var searchBar = document.getElementById("search");
  576. if (searchBar) {
  577. searchBar.onkeydown = this.enter;
  578. }
  579. },
  580. //monitor方法用于检错、监控修改结果,若出错则调用init方法重新覆盖
  581. monitor: function() {
  582. var searchForm = document.getElementById("search-form");
  583. var searchBar = document.getElementById("search");
  584. var searchBtn = document.getElementById("search-btn");
  585. if ((searchBar && searchBar.onkeydown === null) || (searchBtn && searchBtn.type !== "text") || (
  586. searchBtn && searchBtn.onclick === null)) {
  587. this.initSearch();
  588. }
  589. }
  590. }
  591. //bookMarks对象为主页书签项
  592. var bookMarks = {
  593. //change方法用于改变书签打开方式
  594. change: function(Obj) {
  595. if (Obj.tagName === "A") {
  596. if (settings.get("bookMarks") && Obj.target !== "") {
  597. Obj.target = "";
  598. } else if (!settings.get("bookMarks") && Obj.target !== "_blank") {
  599. Obj.target = "_blank";
  600. }
  601. }
  602. },
  603. //init方法用于遍历书签并调用change方法改变打开方式
  604. init: function() {
  605. var siteBox, aBox, aBoxLen;
  606. var idArray = ["site-box", "site-wrap"];
  607. for (let i = 0; i < idArray.length; i++) {
  608. siteBox = document.getElementById(idArray[i])
  609. if (siteBox) {
  610. break;
  611. }
  612. }
  613. if (siteBox && siteBox.childElementCount > 0) {
  614. for (let i = 0; i < siteBox.childElementCount; i++) {
  615. this.change(siteBox.children[i]);
  616. }
  617. }
  618. },
  619. //monitor方法用于检错程序
  620. monitor: function() {
  621. this.init();
  622. }
  623. }
  624. //serchForcast搜索栏联想词预测相关功能
  625. var serchForcast = {
  626. display: function() {
  627. var keywordBox = document.getElementById("search-keyword-box");
  628. if (keywordBox && !settings.get("serchForcast")) {
  629. keywordBox.remove();
  630. }
  631. },
  632. //click方法用于覆盖原联想词点击方法
  633. click: function(target) {
  634. var searchBar = document.getElementById("search");
  635. searchBar.value = target.innerText;
  636. searchEngine.click();
  637. },
  638. //mouseOver方法用于覆盖原联想词鼠标事件(置于上方)方法
  639. mouseOver: function(target) {
  640. var targetPare = target.parentElement;
  641. if (targetPare && targetPare.childElementCount > 0) {
  642. for (let i = 0; i < targetPare.childElementCount; i++) {
  643. this.mouseLeave(targetPare.children[i]);
  644. }
  645. }
  646. target.style = "background-color: rgb(241, 241, 241);";
  647. },
  648. //mouseLeave方法用于覆盖原联想词鼠标事件(离开)方法
  649. mouseLeave: function(target) {
  650. target.style = "background-color: rgba(255, 255, 255, 0.3);";
  651. },
  652. //change方法用于改变搜索栏联想词相关功能
  653. change: function(keywordBox) {
  654. if (keywordBox) {
  655. keywordBox.innerHTML = keywordBox.innerHTML; //整体覆盖删除原方法
  656. var keyword = keywordBox.children;
  657. if (keyword.length > 0) {
  658. for (let i = 0; i < keyword.length; i++) { //增加新方法
  659. keyword[i].onmouseover = function() {
  660. serchForcast.mouseOver(keyword[i]);
  661. };
  662. keyword[i].onmouseleave = function() {
  663. serchForcast.mouseLeave(keyword[i]);
  664. };
  665. keyword[i].onclick = function() {
  666. serchForcast.click(keyword[i]);
  667. };
  668. }
  669. }
  670. }
  671. },
  672. //close方法用于关闭设置时若未保存重置按键值
  673. close: function() {
  674. var localData = store.get("settingsData");
  675. var localValue = localData.serchForcast;
  676. var settingValue = settings.get("serchForcast");
  677. if (typeof localValue === "boolean" && typeof settingValue === "boolean" && localValue !==
  678. settingValue) {
  679. var targetBtn = document.getElementById("moreSet-Opt-serchForcast-" + localValue);
  680. if (targetBtn) {
  681. targetBtn.click();
  682. }
  683. targetBtn = document.getElementById("new-save-box");
  684. if (targetBtn && targetBtn.style.display !== "none") {
  685. targetBtn.style.display = "none";
  686. }
  687. }
  688. },
  689. //init方法用于初始化相关功能
  690. init: function() {
  691. addLoadEvent(this.display);
  692. this.change();
  693. var closeBtn = document.getElementById("console-close-btn");
  694. if (closeBtn) {
  695. closeBtn.addEventListener("click", serchForcast.close);
  696. }
  697. },
  698. //monitor方法用于检错程序
  699. monitor: function() {
  700. var keywordBox = document.getElementById("search-keyword-box");
  701. if (keywordBox && keywordBox.childElementCount > 0) {
  702. var keywordInitFlag = false;
  703. var keyword = keywordBox.children;
  704. for (let i = 0; i < keyword.length; i++) {
  705. if (keyword[i].onmouseover === null || keyword[i].onmouseleave === null || keyword[i]
  706. .onclick === null) {
  707. keywordInitFlag = true;
  708. break;
  709. }
  710. }
  711. if (keywordInitFlag) {
  712. this.change(keywordBox);
  713. }
  714. }
  715. }
  716. };
  717. //settingsPurify为设置页净化功能
  718. var settingsPurify = {
  719. //init方法用于初始化净化广告
  720. init: function() {
  721. var adObj = document.getElementsByClassName("console-bottom-ad")[0];
  722. if (adObj) {
  723. if (settings.get("settingsPurify") && adObj.style.display !== "none") {
  724. adObj.style.display = "none";
  725. } else if (!settings.get("settingsPurify") && adObj.style.display === "none") {
  726. adObj.style.display = "";
  727. }
  728. }
  729. var bottomBtnBox = document.getElementById("console-bottom-btn-box");
  730. if (bottomBtnBox) {
  731. var bottomBtn = bottomBtnBox.children[1];
  732. if (bottomBtn) {
  733. if (settings.get("settingsPurify") && bottomBtn.innerText === "设为主页") {
  734. bottomBtn.innerText = "移动版";
  735. bottomBtn.href = "/m";
  736. bottomBtn.target = "";
  737. } else if (!settings.get("settingsPurify") && bottomBtn.innerText !== "设为主页") {
  738. bottomBtn.innerText = "设为主页";
  739. bottomBtn.href = "/zhuye";
  740. bottomBtn.target = "_blank";
  741. }
  742. }
  743. bottomBtn = bottomBtnBox.children[2];
  744. if (bottomBtn) {
  745. if (settings.get("settingsPurify") && bottomBtn.innerText === "关于") {
  746. bottomBtn.innerText = "问题反馈";
  747. bottomBtn.href = "/contact";
  748. bottomBtn.target = "_blank";
  749. } else if (!settings.get("settingsPurify") && bottomBtn.innerText !== "关于") {
  750. bottomBtn.innerText = "关于";
  751. bottomBtn.href = "/about";
  752. bottomBtn.target = "_blank";
  753. }
  754. }
  755. }
  756. },
  757. //monitor方法用于检错程序
  758. monitor: function() {
  759. this.init();
  760. }
  761. }
  762. //hideRandBg为主页随机背景入口隐藏功能
  763. var hideRandBg = {
  764. //init方法用于初始化入口隐藏
  765. init: function() {
  766. var randBgBtn = document.getElementById("rand-bg-btn");
  767. if (randBgBtn) {
  768. if (settings.get("hideRandBg") && randBgBtn.style.display !== "none") {
  769. randBgBtn.style.display = "none";
  770. } else if (!settings.get("hideRandBg") && randBgBtn.style.display === "none") {
  771. randBgBtn.style.display = "";
  772. }
  773. }
  774. },
  775. //monitor方法用于检错程序
  776. monitor: function() {
  777. this.init();
  778. }
  779. }
  780. //全局变量配置
  781. var saveFlag = false; //saveFlag用于判断是否需要保存增强设置
  782. //启动主程序
  783. settings.on();
  784. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址