简法主页功能增强

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

  1. // ==UserScript==
  2. // @name 简法主页功能增强
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.23
  5. // @description 在简法主页上增加其他个性化设置
  6. // @author tutu辣么可爱
  7. // @include *://*.jianfast.*
  8. // @icon https://s3.bmp.ovh/imgs/2021/08/2a5feb8f5f886e70.png
  9. // @grant GM_openInTab
  10. // @grant GM_info
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. //addLoadEvent方法用于添加window.onload方法且window.onload不会相互覆盖覆盖
  16. function addLoadEvent(newOnload) {
  17. var oldOnload = window.onload;
  18. if (typeof window.onload != 'function') {
  19. window.onload = newOnload;
  20. } else {
  21. window.onload = function() {
  22. oldOnload();
  23. newOnload();
  24. }
  25. }
  26. }
  27. //store为本地存储功能
  28. var store = {
  29. //set方法在localstorage中修改指定JSON数据
  30. set: function(key, val) {
  31. if (!val) {
  32. return;
  33. }
  34. try {
  35. var json = JSON.stringify(val);
  36. if (typeof JSON.parse(json) === "object") { // 验证一下是否为JSON字符串防止保存错误
  37. localStorage.setItem(key, json);
  38. }
  39. } catch (e) {
  40. return false;
  41. }
  42. },
  43. //get方法在localstorage中获取指定JSON数据
  44. get: function(key) {
  45. if (this.has(key)) {
  46. return JSON.parse(localStorage.getItem(key));
  47. }
  48. },
  49. //has方法在localstorage中查询指定JSON数据是否存在
  50. has: function(key) {
  51. if (localStorage.getItem(key)) {
  52. return true;
  53. } else {
  54. return false;
  55. }
  56. },
  57. //del方法在localstorage中删除指定JSON数据
  58. del: function(key) {
  59. localStorage.removeItem(key);
  60. }
  61. };
  62. //settings对象为设置项
  63. var settings = {
  64. settingsData: {
  65. searchBar: true, //true:显示搜索栏;false:隐藏搜索栏
  66. siteBar: true, //true:显示书签栏;false:隐藏书签栏
  67. searchEngine: true, //true:当前标签页打开搜索结果;false:新标签页打开搜索结果
  68. bookMarks: true, //true:当前标签页打开书签网页;false:新标签页打开书签网页
  69. settingsPurify: true, //true:开启广告拦截净化;false:关闭广告拦截净化
  70. hideRandBg: true, //true:开启主页随机背景入口隐藏;false:关闭主页随机背景入口隐藏
  71. serchForcast: true, //true:开启搜索栏联想词预测;false:关闭搜索栏联想词预测
  72. customJsCss: false, //true:开启自定义JS/CSS;false:关闭自定义JS/CSS
  73. customJsCssData: {}, //用于存储自定义JS/CSS
  74. bookmarksFolder: false, //true:添加入口;false:不添加入口
  75. bookmarksUrl: "chrome://bookmarks", //用于存储浏览器书签地址
  76. currentWeather: false, //true:添加天气;false:不添加天气
  77. weatherCity: "", //实况天气城市,若为空则自动ip定位到地级市
  78. weatherAppId: "", //实况天气AppId,若为空则使用默认AppId
  79. weatherAppSecret: "" //实况天气AppSecret,若为空则使用默认AppSecret
  80. },
  81. backupData: {}, //用于备份数据
  82. //get方法获取settings对象settingsData属性
  83. get: function(key) {
  84. return this.settingsData[key];
  85. },
  86. //get方法获取settings对象settingsData所有属性
  87. getAll: function() {
  88. return this.settingsData;
  89. },
  90. //getBackup方法获取settings对象backupData所有属性
  91. getBackup: function() {
  92. return this.backupData;
  93. },
  94. //set方法设置settings对象settingsData属性
  95. set: function(key, value) {
  96. if (typeof value === "boolean" || /^(customJsCssData|bookmarksUrl|weather)/i.test(key)) {
  97. this.settingsData[key] = value;
  98. } else {
  99. console.log("value错误");
  100. }
  101. },
  102. //save方法用于保存设置
  103. save: function() {
  104. store.set("settingsData", this.getAll());
  105. },
  106. //initData方法初始化settings对象属性
  107. initData: function() {
  108. this.backupData = this.settingsData;
  109. var localData = store.get("settingsData");
  110. var settingsData = this.settingsData;
  111. if (localData) {
  112. this.settingsData = {
  113. ...settingsData,
  114. ...localData
  115. };
  116. } else {
  117. store.set("settingsData", this.settingsData);
  118. }
  119. },
  120. //init方法初始化搜索引擎与书签的打开方式
  121. init: function() {
  122. this.initData();
  123. newSettingsPageFn.init();
  124. searchEngine.init();
  125. bookMarks.init();
  126. serchForcast.init();
  127. settingsPurify.init();
  128. hideRandBg.init();
  129. customJsCss.init();
  130. bookmarksFolder.init();
  131. currentWeather.init();
  132. console.log("简法主页功能增强:初始化完成");
  133. },
  134. //monitor方法用于检错、监控修改结果
  135. monitor: function() {
  136. var Timer = setInterval(function() {
  137. searchEngine.monitor();
  138. bookMarks.monitor();
  139. serchForcast.monitor();
  140. settingsPurify.monitor();
  141. hideRandBg.monitor();
  142. customJsCss.monitor();
  143. bookmarksFolder.monitor();
  144. currentWeather.monitor();
  145. }, 500);
  146. console.log("简法主页功能增强:检错程序启动(定时器ID:" + Timer + ")");
  147. },
  148. //on方法用于启动整个程序
  149. on: function() {
  150. if (location.hostname === 'www.jianfast.com' && (location.pathname === "/" || location
  151. .pathname === "/m")) {
  152. console.log("简法主页功能增强:主程序启动");
  153. this.init();
  154. this.monitor();
  155. }
  156. }
  157. }
  158. //newSettingsPageFn为增强设置页
  159. var newSettingsPageFn = {
  160. optData: [{
  161. tittle: "显示主页搜索栏",
  162. value: "searchBar",
  163. choice: [{
  164. t: "开启显示",
  165. v: true
  166. }, {
  167. t: "关闭显示",
  168. v: false
  169. }]
  170. }, {
  171. tittle: "显示主页书签栏",
  172. value: "siteBar",
  173. choice: [{
  174. t: "开启显示",
  175. v: true
  176. }, {
  177. t: "关闭显示",
  178. v: false
  179. }]
  180. }, {
  181. tittle: "搜索结果打开方式",
  182. value: "searchEngine",
  183. choice: [{
  184. t: "当前标签页",
  185. v: true
  186. }, {
  187. t: "新标签页",
  188. v: false
  189. }]
  190. }, {
  191. tittle: "主页书签打开方式",
  192. value: "bookMarks",
  193. choice: [{
  194. t: "当前标签页",
  195. v: true
  196. }, {
  197. t: "新标签页",
  198. v: false
  199. }]
  200. }, {
  201. tittle: "搜索栏联想词预测",
  202. value: "serchForcast",
  203. choice: [{
  204. t: "开启预测",
  205. v: true
  206. }, {
  207. t: "关闭预测",
  208. v: false
  209. }]
  210. }, {
  211. tittle: "广告拦截净化",
  212. value: "settingsPurify",
  213. choice: [{
  214. t: "开启净化",
  215. v: true
  216. }, {
  217. t: "关闭净化",
  218. v: false
  219. }]
  220. }, {
  221. tittle: "隐藏随机背景入口",
  222. value: "hideRandBg",
  223. choice: [{
  224. t: "开启隐藏",
  225. v: true
  226. }, {
  227. t: "关闭隐藏",
  228. v: false
  229. }]
  230. }, {
  231. tittle: "自定义JS/CSS",
  232. value: "customJsCss",
  233. choice: [{
  234. t: "开启自定义",
  235. v: true
  236. }, {
  237. t: "关闭自定义",
  238. v: false
  239. }]
  240. }, {
  241. tittle: "浏览器书签",
  242. value: "bookmarksFolder",
  243. choice: [{
  244. t: "添加入口",
  245. v: true
  246. }, {
  247. t: "关闭功能",
  248. v: false
  249. }]
  250. }, {
  251. tittle: "添加实况天气",
  252. value: "currentWeather",
  253. choice: [{
  254. t: "添加天气",
  255. v: true
  256. }, {
  257. t: "关闭功能",
  258. v: false
  259. }]
  260. }, {
  261. tittle: "关于脚本",
  262. type: "note",
  263. noteData: [{
  264. l: "当前版本",
  265. r: `<span id='versionBtn'>version${GM_info.script.version}</span>`
  266. }, {
  267. l: "版本更新",
  268. r: "<span id='updateBtn'>GreasyFork</span>"
  269. }, {
  270. l: "反馈建议",
  271. r: "<span id='contactBtn'>点此处反馈</span>"
  272. }, {
  273. l: "导入配置",
  274. r: "<span id='importSetBtn'>点此处导入</span>"
  275. }, {
  276. l: "导出配置",
  277. r: "<span id='exportSetBtn'>点此处导出</span>"
  278. }, {
  279. l: "重置配置",
  280. r: "<span id='recoverSetBtn'>点此处重置</span>"
  281. }, {
  282. l: "天气接口",
  283. r: "<span id='weatherApiBtn'>点此处前往</span>"
  284. }]
  285. }],
  286. //clickFn方法为设置选项按钮的点击功能
  287. clickFn: function(id, key) {
  288. var Obj = document.getElementById(id);
  289. var setValue = settings.get(key);
  290. var optValue = Obj.value;
  291. if (setValue !== optValue) {
  292. this.selectBtn(Obj, key, optValue);
  293. this.needSave();
  294. }
  295. },
  296. //selectBtn方法用于选择按钮
  297. selectBtn: function(target, key, value) {
  298. settings.set(key, value);
  299. var targetPar = target.parentElement.children;
  300. for (let i = 0; i < targetPar.length; i++) {
  301. if (targetPar[i].value === value) {
  302. targetPar[i].style.border = "1px solid #2c7bf6";
  303. targetPar[i].style.color = "#2c7bf6";
  304. } else {
  305. targetPar[i].style.border = "1px solid rgba(0, 0, 0, 0.1)";
  306. targetPar[i].style.color = "";
  307. }
  308. }
  309. },
  310. //needSave方法用于显示保存按钮
  311. needSave: function() {
  312. saveFlag = true;
  313. var newSaveBox = document.getElementById("new-save-box");
  314. if (newSaveBox && newSaveBox.style.display === "none") {
  315. newSaveBox.style.display = "flex";
  316. }
  317. var tittleBox = document.getElementById("console-title-box");
  318. if (tittleBox && tittleBox.style.display !== "none") {
  319. tittleBox.style.display = "none";
  320. }
  321. },
  322. //createTittle方法创建一个盛放设置标题的元素对象
  323. createTittle: function(val) {
  324. var Box = document.createElement("div");
  325. Box.setAttribute("class", "console-bigTitle");
  326. Box.innerText = val;
  327. return Box;
  328. },
  329. //createChoiceBtn方法创建一个设置选项按钮对象
  330. createChoiceBtn: function(choice, id) {
  331. var Btn = document.createElement("div");
  332. var BtnID = id + "-" + choice.v;
  333. var key = id.slice("moreSet-Opt-".length);
  334. Btn.style =
  335. "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;";
  336. Btn.innerText = choice.t;
  337. Btn.value = choice.v;
  338. Btn.id = BtnID;
  339. Btn.onclick = function() {
  340. newSettingsPageFn.clickFn(BtnID, key);
  341. };
  342. if (settings.get(key) === choice.v) {
  343. Btn.style.border = "1px solid #2c7bf6";
  344. Btn.style.color = "#2c7bf6";
  345. }
  346. return Btn;
  347. },
  348. //createChoice方法创建一个设置选项按钮对象的集合对象
  349. createChoice: function(value, choice) {
  350. var Box = document.createElement("div");
  351. var BoxID = "moreSet-Opt-" + value;
  352. Box.style =
  353. "width:100%;display:flex;justify-content:center;flex-flow:row wrap;margin-top:15px;";
  354. Box.id = BoxID
  355. var Btn;
  356. if (Array.isArray(choice)) {
  357. for (let i = 0; i < choice.length; i++) {
  358. Btn = this.createChoiceBtn(choice[i], BoxID);
  359. Box.appendChild(Btn);
  360. }
  361. } else {
  362. Btn = this.createChoiceBtn(choice, BoxID);
  363. Box.appendChild(Btn);
  364. }
  365. return Box;
  366. },
  367. //createOpt方法创建一个完整的设置项对象
  368. createOpt: function(tittle, value, choice) {
  369. var ResObj = false;
  370. if (tittle && value && choice) {
  371. ResObj = document.createElement("div");
  372. var newTittle = this.createTittle(tittle);
  373. var newChoice = this.createChoice(value, choice);
  374. ResObj.appendChild(newTittle);
  375. ResObj.appendChild(newChoice);
  376. }
  377. return ResObj;
  378. },
  379. //createNoteText方法创建一个文字性(非选项)的提示对象
  380. createNoteText: function(data) {
  381. var textObj = document.createElement("div");
  382. textObj.style = "width:100%;margin:5px;";
  383. textObj.innerHTML = "<span>" + data.l + "</span>";
  384. if (data.r) {
  385. textObj.innerHTML += "<span> : </span><span style='color:black'>" + data.r + "</span>";
  386. }
  387. return textObj;
  388. },
  389. //createNoteData方法创建一个文字性的提示对象的集合对象
  390. createNoteData: function(noteData) {
  391. var newNoteBox = document.createElement("div");
  392. newNoteBox.style =
  393. "width: 60%;margin:20%;margin-top: 20px; text-align: center; line-height: 23px;";
  394. var newNoteText;
  395. if (Array.isArray(noteData)) {
  396. for (let i = 0; i < noteData.length; i++) {
  397. newNoteText = this.createNoteText(noteData[i]);
  398. newNoteBox.appendChild(newNoteText);
  399. }
  400. } else {
  401. newNoteText = this.createNoteText(noteData);
  402. newNoteBox.appendChild(newNoteText);
  403. }
  404. return newNoteBox;
  405. },
  406. //createNote方法创建一个文字性的完整的提示对象
  407. createNote: function(tittle, noteData) {
  408. var ResObj = false;
  409. if (tittle && noteData) {
  410. ResObj = document.createElement("div");
  411. var newTittle = this.createTittle(tittle);
  412. var newNote = this.createNoteData(noteData);
  413. ResObj.appendChild(newTittle);
  414. ResObj.appendChild(newNote);
  415. }
  416. return ResObj;
  417. },
  418. //createPage方法创建一个增强设置页
  419. createPage: function(val) {
  420. var settingBox = document.createElement("div");
  421. settingBox.id = "console-moreSet-content";
  422. settingBox.style =
  423. "width: 100%;height: 100px;flex-grow: 1;overflow: auto;box-sizing: border-box;padding: 0 25px 0 0;margin: 10px 0;display: none";
  424. var newOpt;
  425. for (let i = 0; i < val.length; i++) {
  426. if (val[i].type) {
  427. if (val[i].type === "note") {
  428. newOpt = this.createNote(val[i].tittle, val[i].noteData);
  429. settingBox.appendChild(newOpt);
  430. }
  431. } else {
  432. newOpt = this.createOpt(val[i].tittle, val[i].value, val[i].choice);
  433. settingBox.appendChild(newOpt);
  434. }
  435. }
  436. document.getElementById("console-box").appendChild(settingBox);
  437. },
  438. //createMenu方法在设置菜单中创建增强设置功能入口
  439. createMenu: function() {
  440. var menuBtn = document.createElement("div");
  441. menuBtn.setAttribute("class", "console-menu-btn");
  442. menuBtn.id = "moreSetBtn";
  443. menuBtn.innerText = "增强设置";
  444. menuBtn.onclick = this.on;
  445. document.getElementById("console-menu-main").appendChild(menuBtn);
  446. },
  447. //createSaveBtn方法创建一个保存按钮对象
  448. createSaveBtn: function() {
  449. var oldSaveBox = document.getElementById("save-box");
  450. var newSaveBox = document.createElement("div");
  451. newSaveBox.style.display = "none";
  452. newSaveBox.id = "new-save-box";
  453. var newSaveBtn = document.createElement("div");
  454. newSaveBtn.style =
  455. "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;";
  456. var newSaveIcon = document.createElement("img");
  457. newSaveIcon.style = "width: 13px;height: 13px;margin-right: 5px;";
  458. newSaveIcon.setAttribute("src", "/static/home/images/console/saveicon.svg");
  459. var newSaveTittle = document.createElement("span");
  460. newSaveTittle.innerText = "保存并应用";
  461. newSaveBtn.onclick = function() {
  462. if (saveFlag) {
  463. settings.save();
  464. saveFlag = false;
  465. console.log("保存增强设置");
  466. setTimeout(function() {
  467. var msgBox = document.getElementById("msg-box");
  468. msgBox.style =
  469. "opacity:0.8;margin-top:50px;display:inline-block;";
  470. msgBox.innerText = "增强设置保存成功";
  471. setTimeout(function() {
  472. location.reload();
  473. }, 500);
  474. }, 300);
  475. }
  476. document.getElementById("console-close-btn").click();
  477. };
  478. newSaveBtn.appendChild(newSaveIcon);
  479. newSaveBtn.appendChild(newSaveTittle);
  480. newSaveBox.appendChild(newSaveBtn);
  481. oldSaveBox.parentElement.insertBefore(newSaveBox, oldSaveBox);
  482. },
  483. //on方法是增强设置页面的启动方法
  484. on: function() {
  485. var moreSetPage = document.getElementById("console-moreSet-content");
  486. if (moreSetPage) {
  487. document.getElementsByClassName("console-title-img")[0].src =
  488. "/static/home/images/console/set1.svg";
  489. document.getElementsByClassName("console-title")[0].innerText = "增强设置";
  490. document.getElementById("console-menu").style.display = "none";
  491. moreSetPage.style.display = "block";
  492. } else {
  493. console.log("增强设置页不存在");
  494. }
  495. },
  496. //off方法是增强设置页面的关闭/隐藏方法
  497. off: function() {
  498. var moreSetPage = document.getElementById("console-moreSet-content");
  499. var newSaveBox = document.getElementById("new-save-box");
  500. if (moreSetPage && moreSetPage.style.display !== "none") {
  501. moreSetPage.style.display = "none";
  502. }
  503. if (newSaveBox.style.display !== "none") {
  504. newSaveBox.style.display = "none";
  505. }
  506. },
  507. //addExtEvent方法用于增加一些额外的事件
  508. addExtEvent: function() {
  509. var target;
  510. //当前版本
  511. target = document.getElementById("versionBtn");
  512. if (target) {
  513. target.onclick = function() {
  514. var msg =
  515. `脚本名称:${GM_info.script.name}\n当前版本:${GM_info.script.version}\n本作作者:${GM_info.script.author}\n检查版本更新、使用帮助等功能,请点击"关于脚本"下方的"GreasyFork"文字`;
  516. console.log(msg);
  517. alert(msg);
  518. }
  519. target.onmouseover = function() {
  520. document.getElementById("versionBtn").style.color = "";
  521. }
  522. target.onmouseleave = function() {
  523. document.getElementById("versionBtn").style.color = "grey";
  524. }
  525. target.style.cursor = "pointer";
  526. target.style.color = "grey";
  527. }
  528. //版本更新
  529. target = document.getElementById("updateBtn");
  530. if (target) {
  531. target.onclick = function() {
  532. location.href = "https://gf.qytechs.cn/zh-CN/scripts/431279";
  533. }
  534. target.onmouseover = function() {
  535. document.getElementById("updateBtn").style.color = "";
  536. }
  537. target.onmouseleave = function() {
  538. document.getElementById("updateBtn").style.color = "grey";
  539. }
  540. target.style.cursor = "pointer";
  541. target.style.color = "grey";
  542. }
  543. //反馈建议
  544. target = document.getElementById("contactBtn");
  545. if (target) {
  546. target.onclick = function() {
  547. location.href = "https://gf.qytechs.cn/zh-CN/scripts/431279/feedback";
  548. }
  549. target.onmouseover = function() {
  550. document.getElementById("contactBtn").style.color = "";
  551. }
  552. target.onmouseleave = function() {
  553. document.getElementById("contactBtn").style.color = "grey";
  554. }
  555. target.style.cursor = "pointer";
  556. target.style.color = "grey";
  557. }
  558. //导入配置
  559. target = document.getElementById("importSetBtn");
  560. if (target) {
  561. target.onclick = function() {
  562. var data = prompt("在这粘贴需要导入的配置数据:");
  563. data = data.trim();
  564. try {
  565. if (data !== null && data !== "") {
  566. data = JSON.parse(data);
  567. store.set("settingsData", data.settingsData);
  568. alert("导入配置成功");
  569. location.reload();
  570. }
  571. } catch (e) {
  572. alert("配置数据错误,导入配置失败");
  573. }
  574. }
  575. target.onmouseover = function() {
  576. document.getElementById("importSetBtn").style.color = "";
  577. }
  578. target.onmouseleave = function() {
  579. document.getElementById("importSetBtn").style.color = "grey";
  580. }
  581. target.style.cursor = "pointer";
  582. target.style.color = "grey";
  583. }
  584. //导出配置
  585. target = document.getElementById("exportSetBtn");
  586. if (target) {
  587. target.onclick = function() {
  588. var exportBox = document.createElement("input");
  589. exportBox.value = "{\"settingsData\":" + JSON.stringify(settings.getAll()) + "}";
  590. document.body.appendChild(exportBox);
  591. exportBox.select();
  592. document.execCommand('copy');
  593. exportBox.remove();
  594. alert("配置数据已成功导出到剪贴板");
  595. }
  596. target.onmouseover = function() {
  597. document.getElementById("exportSetBtn").style.color = "";
  598. }
  599. target.onmouseleave = function() {
  600. document.getElementById("exportSetBtn").style.color = "grey";
  601. }
  602. target.style.cursor = "pointer";
  603. target.style.color = "grey";
  604. }
  605. //重置配置
  606. target = document.getElementById("recoverSetBtn");
  607. if (target) {
  608. target.onclick = function() {
  609. var msg = "即将重置配置数据\n点击确认开始重置";
  610. if (confirm(msg)) {
  611. var data = settings.getBackup();
  612. if (JSON.stringify(data).trim() !== "{}") {
  613. store.set("settingsData", data);
  614. alert("配置数据重置成功");
  615. location.reload();
  616. } else {
  617. msg = "重置配置功能错误,请联系脚本制作者\n点击确认前往反馈";
  618. if (confirm(msg)) {
  619. var btn = document.getElementById("contactBtn");
  620. if (btn) {
  621. btn.click();
  622. }
  623. }
  624. }
  625. }
  626. }
  627. target.onmouseover = function() {
  628. document.getElementById("recoverSetBtn").style.color = "";
  629. }
  630. target.onmouseleave = function() {
  631. document.getElementById("recoverSetBtn").style.color = "grey";
  632. }
  633. target.style.cursor = "pointer";
  634. target.style.color = "grey";
  635. }
  636. //天气接口
  637. target = document.getElementById("weatherApiBtn");
  638. if (target) {
  639. target.onclick = function() {
  640. alert("此API来源于网络,非本脚本开发者所有\n如有天气API方面的问题,请联系API开发者");
  641. open("https://yiketianqi.com/");
  642. }
  643. target.onmouseover = function() {
  644. this.style.color = "";
  645. }
  646. target.onmouseleave = function() {
  647. this.style.color = "grey";
  648. }
  649. target.style.cursor = "pointer";
  650. target.style.color = "grey";
  651. }
  652. //自定义JS/CSS
  653. target = document.getElementById("moreSet-Opt-customJsCss-true");
  654. if (target) {
  655. target.addEventListener("click", function() {
  656. customJsCss.clickFn();
  657. });
  658. }
  659. //浏览器书签
  660. target = document.getElementById("moreSet-Opt-bookmarksFolder-true");
  661. if (target) {
  662. target.addEventListener("click", function() {
  663. bookmarksFolder.clickFn();
  664. });
  665. }
  666. //实况天气
  667. target = document.getElementById("moreSet-Opt-currentWeather-true");
  668. if (target) {
  669. target.addEventListener("click", function() {
  670. currentWeather.clickFn();
  671. });
  672. }
  673. },
  674. //initPC方法是针对PC模式的增强设置初始化方法,是增强设置的启动方法
  675. initPC: function() {
  676. var consoleBox = document.getElementById("console-box");
  677. if (consoleBox) {
  678. var closeBtn = document.getElementById("console-close-btn");
  679. if (closeBtn) {
  680. closeBtn.addEventListener("click", newSettingsPageFn.off);
  681. }
  682. this.createMenu();
  683. this.createSaveBtn();
  684. this.createPage(this.optData);
  685. this.addExtEvent();
  686. }
  687. },
  688. //initMobile方法是针对Mobile模式的增强设置初始化方法,是增强设置的启动方法
  689. initMobile: function() {
  690. var menuWrap = document.getElementById("menu-wrap");
  691. if (menuWrap) {
  692. var menuObj = menuWrap.children[1];
  693. if (menuObj && menuObj.tagName === "UL") {
  694. var newOpt = document.createElement("li");
  695. newOpt.style = "cursor:pointer;"
  696. newOpt.innerHTML = "<img src='/static/home/images/console/set1.svg'/><span>增强设置</span>";
  697. newOpt.onclick = function() {
  698. var res = confirm("增强设置请前往电脑版操作,点击确认前往电脑版");
  699. if (res) {
  700. location.href = "https://www.jianfast.com/?pc=1";
  701. }
  702. }
  703. menuObj.appendChild(newOpt);
  704. }
  705. var menuNotice = document.getElementById("menu-notice");
  706. var newNotice = "<div>" + menuNotice.children[1].innerText +
  707. "</div><div>对增强设置进行修改请前往电脑版网页操作</div><div>增强设置-搜索结果打开方式仅对电脑版生效</div>";
  708. menuNotice.children[1].innerHTML = newNotice;
  709. }
  710. },
  711. //init方法调用initPC方法与initMobile方法初始化增强设置,是对外统一调用的初始化方法
  712. init: function() {
  713. this.initPC();
  714. this.initMobile();
  715. }
  716. };
  717. //searchEngine对象为搜索引擎项
  718. var searchEngine = {
  719. //change方法用于改变搜索按钮类型,从而便于覆盖搜索打开方式
  720. change: function() {
  721. var searchBtn = document.getElementById("search-btn");
  722. if (searchBtn) {
  723. searchBtn.type = "text";
  724. }
  725. },
  726. //click方法用于覆盖原搜索按钮点击方法
  727. click: function() {
  728. if (location.href.search("jianfast.com/m") === -1) {
  729. var searchBar = document.getElementById("search");
  730. var url = searchBar.getAttribute("data-engine-start");
  731. var val = searchBar.value;
  732. if (settings.get("searchEngine")) {
  733. location.href = url + val;
  734. } else {
  735. open(url + val);
  736. }
  737. }
  738. },
  739. //enter方法用于覆盖原回车搜索方法
  740. enter: function(event) {
  741. if (event.keyCode === 13) {
  742. searchEngine.click();
  743. }
  744. },
  745. //display方法用于显示或隐藏搜索栏
  746. display: function() {
  747. var searchBar = document.getElementById("search-wrap");
  748. if (searchBar) {
  749. if (settings.get("searchBar") && searchBar.style.display === "none") {
  750. searchBar.style.display = "flex";
  751. } else if (!settings.get("searchBar") && searchBar.style.display !== "none") {
  752. searchBar.style.display = "none";
  753. }
  754. }
  755. },
  756. //init方法用于初始化搜索引擎,覆盖新方法
  757. init: function() {
  758. searchEngine.change();
  759. this.display();
  760. var searchBtn = document.getElementById("search-btn");
  761. if (searchBtn) {
  762. searchBtn.onclick = this.click;
  763. }
  764. var searchBar = document.getElementById("search");
  765. if (searchBar) {
  766. searchBar.onkeydown = this.enter;
  767. }
  768. },
  769. //monitor方法用于检错、监控修改结果,若出错则调用init方法重新覆盖
  770. monitor: function() {
  771. this.display();
  772. var searchForm = document.getElementById("search-form");
  773. var searchBar = document.getElementById("search");
  774. var searchBtn = document.getElementById("search-btn");
  775. if ((searchBar && searchBar.onkeydown === null) || (searchBtn && searchBtn.type !== "text") || (
  776. searchBtn && searchBtn.onclick === null)) {
  777. this.init();
  778. }
  779. }
  780. }
  781. //bookMarks对象为主页书签项
  782. var bookMarks = {
  783. //change方法用于改变书签打开方式
  784. change: function(Obj) {
  785. if (Obj.tagName === "A") {
  786. if (settings.get("bookMarks") && Obj.target !== "") {
  787. Obj.target = "";
  788. } else if (!settings.get("bookMarks") && Obj.target !== "_blank") {
  789. Obj.target = "_blank";
  790. }
  791. }
  792. },
  793. //display方法用于显示或隐藏书签栏
  794. display: function() {
  795. var siteBar = document.getElementById("site-wrap");
  796. if (siteBar) {
  797. if (settings.get("siteBar") && siteBar.style.display === "none") {
  798. siteBar.style.display = "flex";
  799. } else if (!settings.get("siteBar") && siteBar.style.display !== "none") {
  800. siteBar.style.display = "none";
  801. }
  802. }
  803. },
  804. //init方法用于遍历书签并调用change方法改变打开方式
  805. init: function() {
  806. this.display();
  807. var siteBox, aBox, aBoxLen;
  808. var idArray = ["site-box", "site-wrap"];
  809. for (let i = 0; i < idArray.length; i++) {
  810. siteBox = document.getElementById(idArray[i])
  811. if (siteBox) {
  812. break;
  813. }
  814. }
  815. if (siteBox && siteBox.childElementCount > 0) {
  816. for (let i = 0; i < siteBox.childElementCount; i++) {
  817. this.change(siteBox.children[i]);
  818. }
  819. }
  820. },
  821. //monitor方法用于检错程序
  822. monitor: function() {
  823. this.init();
  824. }
  825. }
  826. //serchForcast搜索栏联想词预测相关功能
  827. var serchForcast = {
  828. display: function() {
  829. var keywordBox = document.getElementById("search-keyword-box");
  830. if (keywordBox && !settings.get("serchForcast")) {
  831. keywordBox.remove();
  832. }
  833. },
  834. //click方法用于覆盖原联想词点击方法
  835. click: function(target) {
  836. var searchBar = document.getElementById("search");
  837. searchBar.value = target.innerText;
  838. searchEngine.click();
  839. },
  840. //mouseOver方法用于覆盖原联想词鼠标事件(置于上方)方法
  841. mouseOver: function(target) {
  842. var targetPare = target.parentElement;
  843. if (targetPare && targetPare.childElementCount > 0) {
  844. for (let i = 0; i < targetPare.childElementCount; i++) {
  845. this.mouseLeave(targetPare.children[i]);
  846. }
  847. }
  848. target.style = "background-color: rgb(241, 241, 241);";
  849. },
  850. //mouseLeave方法用于覆盖原联想词鼠标事件(离开)方法
  851. mouseLeave: function(target) {
  852. target.style = "background-color: rgba(255, 255, 255, 0.3);";
  853. },
  854. //change方法用于改变搜索栏联想词相关功能
  855. change: function(keywordBox) {
  856. if (keywordBox) {
  857. keywordBox.innerHTML = keywordBox.innerHTML; //整体覆盖删除原方法
  858. var keyword = keywordBox.children;
  859. if (keyword.length > 0) {
  860. for (let i = 0; i < keyword.length; i++) { //增加新方法
  861. keyword[i].onmouseover = function() {
  862. serchForcast.mouseOver(keyword[i]);
  863. };
  864. keyword[i].onmouseleave = function() {
  865. serchForcast.mouseLeave(keyword[i]);
  866. };
  867. keyword[i].onclick = function() {
  868. serchForcast.click(keyword[i]);
  869. };
  870. }
  871. }
  872. }
  873. },
  874. //close方法用于关闭设置时若未保存重置按键值
  875. close: function() {
  876. var localData = store.get("settingsData");
  877. var localValue = localData.serchForcast;
  878. var settingValue = settings.get("serchForcast");
  879. if (typeof localValue === "boolean" && typeof settingValue === "boolean" && localValue !==
  880. settingValue) {
  881. var targetBtn = document.getElementById("moreSet-Opt-serchForcast-" + localValue);
  882. if (targetBtn) {
  883. targetBtn.click();
  884. }
  885. targetBtn = document.getElementById("new-save-box");
  886. if (targetBtn && targetBtn.style.display !== "none") {
  887. targetBtn.style.display = "none";
  888. }
  889. }
  890. },
  891. //init方法用于初始化相关功能
  892. init: function() {
  893. addLoadEvent(this.display);
  894. this.change();
  895. var closeBtn = document.getElementById("console-close-btn");
  896. if (closeBtn) {
  897. closeBtn.addEventListener("click", serchForcast.close);
  898. }
  899. },
  900. //monitor方法用于检错程序
  901. monitor: function() {
  902. var keywordBox = document.getElementById("search-keyword-box");
  903. if (keywordBox && keywordBox.childElementCount > 0) {
  904. var keywordInitFlag = false;
  905. var keyword = keywordBox.children;
  906. for (let i = 0; i < keyword.length; i++) {
  907. if (keyword[i].onmouseover === null || keyword[i].onmouseleave === null || keyword[i]
  908. .onclick === null) {
  909. keywordInitFlag = true;
  910. break;
  911. }
  912. }
  913. if (keywordInitFlag) {
  914. this.change(keywordBox);
  915. }
  916. }
  917. }
  918. };
  919. //settingsPurify为广告拦截净化功能
  920. var settingsPurify = {
  921. //init方法用于初始化净化广告
  922. init: function() {
  923. var adObj = document.getElementsByClassName("console-bottom-ad");
  924. if (adObj && adObj.length > 0) {
  925. for (let i = 0; i < adObj.length; i++) {
  926. if (settings.get("settingsPurify") && adObj[i].style.display !== "none") {
  927. adObj[i].style.display = "none";
  928. } else if (!settings.get("settingsPurify") && adObj[i].style.display === "none") {
  929. adObj[i].style.display = "";
  930. }
  931. }
  932. }
  933. adObj = document.getElementById("hongbao-btn");
  934. if (adObj) {
  935. if (settings.get("settingsPurify") && adObj.style.display !== "none") {
  936. adObj.style.display = "none";
  937. } else if (!settings.get("settingsPurify") && adObj.style.display === "none") {
  938. adObj.style.display = "";
  939. }
  940. }
  941. var bottomBtnBox = document.getElementById("console-bottom-btn-box");
  942. if (bottomBtnBox.childElementCount > 0) {
  943. bottomBtnBox = bottomBtnBox.children;
  944. var bottomBtn;
  945. for (let i = 0; i < bottomBtnBox.length; i++) {
  946. bottomBtn = bottomBtnBox[i];
  947. if (bottomBtn) {
  948. if (settings.get("settingsPurify")) {
  949. if (bottomBtn.innerText === "设为主页") {
  950. bottomBtn.innerText = "移动版";
  951. bottomBtn.href = "/m";
  952. bottomBtn.target = "";
  953. } else if (bottomBtn.innerText === "关于") {
  954. bottomBtn.innerText = "问题反馈";
  955. bottomBtn.href = "/contact";
  956. bottomBtn.target = "_blank";
  957. }
  958. } else if (!settings.get("settingsPurify")) {
  959. if (bottomBtn.innerText === "设为主页") {
  960. bottomBtn.innerText = "设为主页";
  961. bottomBtn.href = "/zhuye";
  962. bottomBtn.target = "_blank";
  963. } else if (bottomBtn.innerText === "关于") {
  964. bottomBtn.innerText = "关于";
  965. bottomBtn.href = "/about";
  966. bottomBtn.target = "_blank";
  967. }
  968. }
  969. }
  970. }
  971. }
  972. },
  973. //monitor方法用于检错程序
  974. monitor: function() {
  975. this.init();
  976. }
  977. }
  978. //hideRandBg为主页随机背景入口隐藏功能
  979. var hideRandBg = {
  980. //init方法用于初始化入口隐藏
  981. init: function() {
  982. var randBgBtn = document.getElementById("rand-bg-btn");
  983. if (randBgBtn) {
  984. if (settings.get("hideRandBg") && randBgBtn.style.display !== "none") {
  985. randBgBtn.style.display = "none";
  986. } else if (!settings.get("hideRandBg") && randBgBtn.style.display === "none") {
  987. randBgBtn.style.display = "";
  988. }
  989. }
  990. },
  991. //monitor方法用于检错程序
  992. monitor: function() {
  993. this.init();
  994. }
  995. }
  996. //自定义JS/CSS
  997. var customJsCss = {
  998. getData: function(type, originData, extraMsg) {
  999. var data, res;
  1000. var msg = "请输入自定义" + type + "\n点击确定,保存自定义" + type + "; 点击取消,删除自定义" + type;
  1001. if (extraMsg) {
  1002. msg = msg + "\n\n" + extraMsg;
  1003. }
  1004. if (!originData) {
  1005. originData = "";
  1006. }
  1007. data = prompt(msg, originData);
  1008. if (typeof data === "string") {
  1009. data = data.trim();
  1010. }
  1011. if (data) {
  1012. res = data;
  1013. } else {
  1014. res = "";
  1015. }
  1016. console.log("自定义" + type + ":" + res);
  1017. return res;
  1018. },
  1019. clickFn: function() {
  1020. var data = settings.get("customJsCssData");
  1021. data.js = this.getData("JS", data.js, "注意:extraCustomJS()为自定义JS的入口方法,请避免将方法名命名为extraCustomJS");
  1022. data.css = this.getData("CSS", data.css);
  1023. settings.set("customJsCssData", data);
  1024. if (!data.js && !data.css) {
  1025. alert("自定义JS/CSS已删除,将自动选择关闭自定义");
  1026. var falseBtn = document.getElementById("moreSet-Opt-customJsCss-false");
  1027. if (falseBtn) {
  1028. falseBtn.click();
  1029. }
  1030. }
  1031. newSettingsPageFn.needSave();
  1032. },
  1033. on: function() {
  1034. var data = settings.get("customJsCssData");
  1035. var eleBox = document.createElement("div");
  1036. eleBox.id = "customJsCssBox";
  1037. if (data.js) {
  1038. var JSele = document.createElement("script");
  1039. JSele.id = "customJS";
  1040. JSele.innerHTML = "function extraCustomJS(){\r\n\ttry{\r\n\t" + data.js +
  1041. "\r\n\t}catch(e){\r\n\tvar msg='自定义JS错误';\r\n\tconsole.log(msg);\r\n\talert(msg);\r\n\t}\r\n\t}\r\n\textraCustomJS();";
  1042. eleBox.appendChild(JSele);
  1043. }
  1044. if (data.js) {
  1045. var CSSele = document.createElement("style");
  1046. CSSele.id = "customCSS";
  1047. CSSele.innerHTML = data.css;
  1048. eleBox.appendChild(CSSele);
  1049. }
  1050. var bodyFirstEle = document.body.children[0];
  1051. document.body.insertBefore(eleBox, bodyFirstEle);
  1052. },
  1053. off: function() {
  1054. var eleBox = document.getElementById("customJsCssBox");
  1055. if (eleBox) {
  1056. eleBox.remove();
  1057. }
  1058. },
  1059. init: function() {
  1060. if (settings.get("customJsCss")) {
  1061. this.on();
  1062. }
  1063. },
  1064. monitor: function() {
  1065. var eleBox = document.getElementById("customJsCssBox");
  1066. if (settings.get("customJsCss") && !eleBox) {
  1067. this.on();
  1068. } else if (!settings.get("customJsCss") && eleBox) {
  1069. this.off();
  1070. }
  1071. }
  1072. };
  1073. //bookmarksFolder浏览器书签
  1074. var bookmarksFolder = {
  1075. //on方法用于启动
  1076. on: function() {
  1077. let bookmarksContainer = document.getElementById("site-box");
  1078. if (bookmarksContainer && bookmarksContainer.firstElementChild) {
  1079. let newSite = bookmarksContainer.querySelector("#open_bookmarks_folder_btn");
  1080. if (newSite) {
  1081. return false;
  1082. }
  1083. newSite = bookmarksContainer.firstElementChild.cloneNode(true);
  1084. newSite.id = "open_bookmarks_folder_btn";
  1085. bookmarksContainer.appendChild(newSite);
  1086. newSite.href = "javascript:void(0);";
  1087. console.log(bookmarksContainer.firstChild)
  1088. newSite.getElementsByTagName("img")[0].src = "static/home/images/defaultsicon/9.png";
  1089. newSite.getElementsByClassName("site-title")[0].innerText = "浏览器书签";
  1090. newSite.onclick = function() {
  1091. let url = settings.get("bookmarksUrl");
  1092. url = url ? url : "chrome://bookmarks";
  1093. GM_openInTab(url, false);
  1094. }
  1095. }
  1096. },
  1097. //off方法用于关闭
  1098. off: function() {
  1099. let target = document.getElementById("open_bookmarks_folder_btn");
  1100. if (target) {
  1101. target.remove();
  1102. }
  1103. },
  1104. //clickFn方法为设置点击功能
  1105. clickFn: function() {
  1106. let url = settings.get("bookmarksUrl");
  1107. url = url ? url : "chrome://bookmarks";
  1108. url = prompt("请输入浏览器书签地址", url);
  1109. if (url && typeof url === "string") {
  1110. settings.set("bookmarksUrl", url);
  1111. newSettingsPageFn.needSave();
  1112. }
  1113. },
  1114. //init方法用于初始化添加一个书签按钮
  1115. init: function() {
  1116. if (settings.get("bookmarksFolder")) {
  1117. this.on();
  1118. }
  1119. },
  1120. //monitor方法用于检错程序
  1121. monitor: function() {
  1122. this.init();
  1123. }
  1124. }
  1125. //currentWeather实况天气
  1126. var currentWeather = {
  1127. num: 0,
  1128. ajax: function() {
  1129. var id = settings.get("weatherAppId"),
  1130. secret = settings.get("weatherAppSecret"),
  1131. city = settings.get("weatherCity");
  1132. id = id ? id : "23035354", secret = secret ? secret : "8YvlPNrz", city = city ?
  1133. `&city${(/^\d+$/.test(city)?"id":"")}=${city}` : ""
  1134. var url =
  1135. `https://yiketianqi.com/api?unescape=1&version=v1&appid=${id}&appsecret=${secret}${city}`;
  1136. console.log(url);
  1137. $.ajax({
  1138. url: url,
  1139. type: "get",
  1140. dataType: "json",
  1141. success: function(res) {
  1142. var data = res.data[0];
  1143. var weather =
  1144. `${res.city}-${data.wea}-${data.air_level.length>1?data.air_level:"空气"+data.air_level}-气温${data.tem}(${data.tem1}/${data.tem2})`
  1145. .replaceAll("℃", "°C");
  1146. var time = new Date().toLocaleString();
  1147. $("#search").attr("placeholder", weather);
  1148. localStorage.setItem("currentWeatherCache", JSON.stringify({
  1149. "t": time,
  1150. "w": weather
  1151. }))
  1152. }
  1153. })
  1154. },
  1155. //on方法用于启动
  1156. on: function() {
  1157. if (this.num === 0) {
  1158. var data = localStorage.getItem("currentWeatherCache");
  1159. if (data) {
  1160. data = JSON.parse(data);
  1161. var pT = new Date(data.t),
  1162. cT = new Date();
  1163. var gap = cT.getTime() - pT.getTime();
  1164. if (gap > 3 * 3600 * 1000 || cT.toLocaleDateString() !== pT.toLocaleDateString()) {
  1165. this.ajax();
  1166. } else if ($("#search").attr("placeholder") !== data.w) {
  1167. $("#search").attr("placeholder", data.w);
  1168. }
  1169. } else {
  1170. this.ajax();
  1171. }
  1172. }
  1173. this.num = (this.num < 1200) ? (this.num + 1) : 0; //10min检查一次cache
  1174. },
  1175. //off方法用于关闭
  1176. off: function() {
  1177. $("#search").attr("placeholder", "");
  1178. },
  1179. // userInput方法为用户输入保存相关信息
  1180. userInput: function(data, key, msg) {
  1181. data = prompt(msg, data);
  1182. if (data && typeof data === "string") {
  1183. settings.set(key, data);
  1184. newSettingsPageFn.needSave();
  1185. }
  1186. },
  1187. //clickFn方法为设置点击功能
  1188. clickFn: function() {
  1189. let city = settings.get("weatherCity"),
  1190. id = settings.get("weatherAppId"),
  1191. secret = settings.get("weatherAppSecret"),
  1192. msg;
  1193. city = city ? city : "", id = id ? id : "", secret = secret ? secret : "";
  1194. msg = "请输入实况天气城市名(可精确到区县一级,例如:浦东新区、崇明、朝阳)或城市id。若为空,则自动使用ip定位到地级市一级\n城市id请点击“关于脚本-天气接口”获取";
  1195. this.userInput(city, "weatherCity", msg);
  1196. msg = "请输入实况天气API的AppId。若为空,自动使用公共AppId\n个人AppId请点击“关于脚本-天气接口”获取";
  1197. this.userInput(id, "weatherAppId", msg);
  1198. msg = "请输入实况天气API的AppSecret。若为空,自动使用公共AppSecret\n个人AppSecret请点击“关于脚本-天气接口”获取";
  1199. this.userInput(id, "weatherAppSecret", msg);
  1200. localStorage.setItem("currentWeatherCache", "");
  1201. this.num = 0;
  1202. },
  1203. //init方法用于初始化添加一个书签按钮
  1204. init: function() {
  1205. if (settings.get("currentWeather")) {
  1206. this.on();
  1207. }
  1208. },
  1209. //monitor方法用于检错程序
  1210. monitor: function() {
  1211. this.init();
  1212. }
  1213. }
  1214. //全局变量配置
  1215. var saveFlag = false; //saveFlag用于判断是否需要保存增强设置
  1216. //启动主程序
  1217. settings.on();
  1218. })();

QingJ © 2025

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