OnePlusBBS QuickKey

一加社区快捷键

当前为 2022-02-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name OnePlusBBS QuickKey
  3. // @description 一加社区快捷键
  4. // @namespace https://greasyfork.org/
  5. // @author choosezzz
  6. // @version 3.3
  7. // @match https://www.oneplusbbs.com/forum*
  8. // @match https://www.oneplusbbs.com/thread*
  9. // @match https://www.oneplusbbs.com/home*
  10. // @match https://www.oneplusbbs.com/
  11. // @icon https://static.oneplus.cn/data/attachment/common/4c/common_121_icon.png
  12. // @require https://lib.baomitu.com/vue/2.6.14/vue.js
  13. // @grant GM_addStyle
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. function $id(doc_id) {
  18. return document.getElementById(doc_id);
  19. }
  20. function $class(class_name) {
  21. return document.getElementsByClassName(class_name);
  22. }
  23. var minAutoTime = 0.2;
  24. var unitTime = 1540;
  25. (function() {
  26.  
  27. //发帖编辑框禁用脚本
  28. if (document.getElementById("editorbox") || document.getElementById("editorheader")) {
  29. return;
  30. }
  31. //settings
  32. appendSettingDiv();
  33. //css
  34. GM_addStyle("#setting_mount{font-size:15px;width:400px;z-index:999;background-color:white;position: fixed;top:35%;left:35%;border-radius:5px;box-shadow:3px 3px 10px red}");
  35. GM_addStyle("#setting_content{padding:2px;border-top:2px solid black;}");
  36. GM_addStyle(".setting_op{background:#34aff4;width:50px;padding:3px 20px;}.setting_op:hover{background:#EEDA0A;color:#ffffff;cursor:Pointer;}");
  37. GM_addStyle(".setting_menu{background:#3dfafe;width:50px;padding:2px 20px;}.setting_menu:hover{background:red;color:#ffffff;cursor:Pointer;}");
  38. GM_addStyle(".space_span{padding:3px 10px;}");
  39. GM_addStyle(".space_span_more{padding:3px 60px;}");
  40. GM_addStyle(".item_div{text-align:center;width:100%;margin:10px 0px}");
  41. //shadow div
  42. GM_addStyle("#shadow_div{z-index:9999;position: fixed;left:0;top:0;width:100%;height:100%;background:gray;opacity:0.5;}");
  43. //confirm div
  44. GM_addStyle("#confirm_div{font-size: 18px;position: fixed;background:#C4DDD9;z-index:10000;text-align:center;padding:20px 20px;top:35%;left:39%;border-radius:5px;box-shadow:3px 3px 5px red;}");
  45. GM_addStyle(".confirm_span{background:#2AA8;padding:3px 10px;border-radius:2px;margin:30px 30px;}");
  46. GM_addStyle(".confirm_span:hover{background:red;color:white;cursor:Pointer;}");
  47. //float menu div
  48. GM_addStyle("#float_menu{z-index:999;position: fixed;left:95%;top:55%;min-width:50px;}");
  49. GM_addStyle(".fast_menu{background:#FAD;text-align:center;padding:2px 5px;margin:1px 1px;border:1px solid red;border-radius:10px}");
  50. GM_addStyle(".fast_menu:hover{background:#DDD;color:blue;cursor:Pointer}");
  51. //自动刷新
  52. autoReflash();
  53.  
  54. var href = window.location.href;
  55. //帖子页
  56. if (href.indexOf("thread-") != -1 || href.indexOf("viewthread") != -1) {
  57. var modMenu = $id("modmenu");
  58. if (!modMenu) {
  59. console.log("当前板块无权限");
  60. return;
  61. }
  62. autoScroll();
  63. appendConfirmDiv();
  64. appendFloatMenu();
  65. }
  66. document.onkeydown = function(event) {
  67. var href = window.location.href;
  68. var e = event || window.event;
  69. if (!e) {
  70. return;
  71. }
  72. if (e.ctrlKey && e.keyCode == 83) {
  73. stopDefault(e);
  74. settingApp.ctrlShow();
  75. }
  76. //个人主页
  77. if (href.search("homemod-space-uid*") != -1) {
  78. //Ctrl+Alt
  79. if (e.altKey && e.ctrlKey) {
  80. stopDefault(e);
  81. var uid = href.replace(/https:\/\/www.oneplusbbs.com\/homemod-space-uid-/g, "").replace(/.html/g, "");
  82. $id("a_sendpm_" + uid).click();
  83. }
  84. }
  85.  
  86. //Ctrl+number
  87. if (((e.keyCode >= 49 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 105)) && e.ctrlKey) {
  88. stopDefault(e);
  89. var msgId = e.keyCode - 96 < 0 ? e.keyCode - 48 : e.keyCode - 96;
  90. quickPaste(msgId);
  91. }
  92.  
  93. //普通帖子页
  94. if (href.indexOf("thread-") != -1 || href.indexOf("viewthread") != -1) {
  95. handlePost(e);
  96. }
  97.  
  98. //列表页
  99. if (href.indexOf("forum-") != -1 || href.indexOf("forumdisplay") != -1) {
  100. handleList(e);
  101. }
  102.  
  103. }
  104. })();
  105.  
  106. function appendSettingDiv() {
  107. var settingMount = document.createElement("div");
  108. settingMount.innerHTML = '<div id="setting_mount" v-show="isShow">' +
  109. //tips div
  110. '<div @mousedown="handleMove" @mouseover="handleOver" @mouseout="handleOut" style="padding: 3px;background: #aadcdf;text-align: center;">' +
  111. '<span>【使用 Ctrl+S 打开/关闭 设置选项】</span></div>' +
  112. '<div v-show="tips != null && tips.length!=0" style="border-top:2px solid black;text-align: center;background: red;font-size: 16px;color:yellow;">{{tips}}</div>' +
  113. //menu div
  114. '<div style="text-align: center;border-top: 2px solid black; padding: 2px 2px">' +
  115. '<span class="setting_menu" @click="quickKeySetting">快捷键设置</span><span class="space_span"></span>' +
  116. '<span class="setting_menu" @click="floatMenuSetting">悬浮菜单设置</span><span class="space_span"></span>' +
  117. '<span class="setting_menu" @click="otherSetting">其他设置</span>'+
  118. '</div>' +
  119. //main div start
  120. '<div id="setting_content" style="height: 250px">' +
  121. //quickKeySetting div
  122. '<div v-show="quickKeyShow" v-for="item of 9" :key="item" style="padding-left: 12px;padding-top: 2px;">' +
  123. '<span>Ctrl+{{item}}:</span>' +
  124. '<input type="text" style="width: 77%" v-model="quickMsg[item-1]"><span v-if="item==1" style="font-size:11px">✔</span>' +
  125. '</div>' +
  126. //floatMenuSetting div
  127. '<div v-show="floatMenuShow" style="padding: 19px 5px; text-align: left;">' +
  128. '<div v-for= "item of 5" >'+
  129. '<div class="item_div" :key="item">'+
  130. '#{{item}}: <input type="text" v-model="menuName[item-1]" style="width: 20%">'+
  131. '操作原因 : <input type="text" v-model="menuReason[item-1]" style="width: 50%">'+
  132. '</div></div>'+
  133. '<span style="margin-left: 5px"></span>自动提交:<input type="checkbox" v-model="autoCommitDel" :checked="autoCommitDel" style="zoom:130%">'+
  134. '<span v-show="autoCommitDel">提交延时:<input type="text" v-model="autoCommitDelTime" placeholder="秒" style="width: 25%"><sub style="color:red;">不能低于 ' + minAutoTime + ' s </sub></span>'+
  135. '</div>' +
  136. //otherSetting div
  137. '<div v-show="otherShow" style="padding-left: 12px;padding-top: 4px;">' +
  138. '定时刷新[秒]:<input type="number" v-model="reflashTime" style="width: 25%" min="300">' +
  139. '<input type="radio" name="reloadTarget" @click="currentPageReload" :checked="currentChecked"> 当前页面 ' +
  140. '<input type="radio" name="reloadTarget" @click="globalReload" :checked="globalChecked"> 全局' +
  141. '<br><hr>删除时自动勾选:<input type="checkbox" v-model="autoRecord" :checked="autoRecord" style="zoom:130%"> 违规登记 '+
  142. '<input type="checkbox" v-model="autoSend" :checked="autoSend" style="zoom:130%"> 通知作者' +
  143. '<br><hr>自动勾选延时:<input type="text" v-model="autoCheckTime" style="width: 25%"> 秒 <br><sub style="color:red;"> 不能低于 ' + minAutoTime + ' s , 功能异常时建议适当调整延时时间</sub>'+
  144. '<br><hr>自动定位到上一次操作位置:<input type="checkbox" v-model="autoScroll" :checked="autoScroll" style="zoom:130%">'+
  145. '</div>' +
  146. // main div end
  147. '</div>' +
  148. //save div
  149. '<div style="text-align: center;padding: 4px;border-top:2px solid black;">' +
  150. '<span class="setting_op" @click="ctrlShow">关闭</span>' +
  151. '<span class="space_span_more"> | </span>' +
  152. '<span class="setting_op" @click="saveSettings">{{saveTips}}</span>' +
  153. '</div>' +
  154. // all end
  155. '</div>';
  156. document.body.appendChild(settingMount);
  157. }
  158. var settingApp = new Vue({
  159. el: "#setting_mount",
  160. data: {
  161. isShow: false,
  162. tips: "",
  163. saveTips: "保存",
  164. quickMsg: ["请勿灌水或回复与帖子无关的内容", "请勿发布纯标题无内容贴"],
  165. reflashTime: 0,
  166. autoRecord: parseBoolean(localStorage.autoRecord),
  167. autoSend: parseBoolean(localStorage.autoSend),
  168. timeOut: 500,
  169. currentChecked: false,
  170. globalChecked: false,
  171. reloadTarget: window.location.href,
  172. quickKeyShow: true,
  173. floatMenuShow: false,
  174. otherShow: false,
  175. autoScroll: parseBoolean(localStorage.autoScroll),
  176. menuName:["灌水删除"],
  177. menuReason:["请勿灌水回帖"],
  178. autoCommitDel: parseBoolean(localStorage.autoCommitDel),
  179. autoCommitDelTime: minAutoTime,
  180. autoCheckTime: minAutoTime
  181. },
  182. methods: {
  183. ctrlShow: function() {
  184. this.isShow = !this.isShow;
  185. if (this.isShow) {
  186. let msg = getQuickMsg();
  187. if (null != msg) {
  188. this.quickMsg = msg;
  189. }
  190.  
  191. let currentReloadTime = localStorage.getItem(this.getUrlId());
  192. if (currentReloadTime) {
  193. this.currentChecked = true;
  194. this.reflashTime = currentReloadTime;
  195. } else {
  196. this.globalChecked = true;
  197. this.reflashTime = localStorage.reflashTime;
  198. }
  199. let menuNameArr = getArrFromStorage("menuName", "$");
  200. if (menuNameArr != null) {
  201. this.menuName = menuNameArr;
  202. }
  203. let menuReasonArr = getArrFromStorage("menuReason", "$");
  204. if (menuReasonArr != null) {
  205. this.menuReason = menuReasonArr;
  206. }
  207. if (localStorage.autoCommitDelTime) {
  208. this.autoCommitDelTime = localStorage.autoCommitDelTime;
  209. }
  210. if (localStorage.autoCheckTime) {
  211. this.autoCheckTime = localStorage.autoCheckTime;
  212. }
  213. }
  214. },
  215. handleOver: function(event) {
  216. let ev = event || window.event;
  217. let moveBar = event.target;
  218. moveBar.style.cursor = "move";
  219. },
  220. handleOut: function(event){
  221. let ev = event || window.event;
  222. let moveBar = event.target;
  223. moveBar.style.cursor = "default";
  224. },
  225. handleMove: function(event) {
  226. let ev = event || window.event;
  227. let moveBar = event.target;
  228. let Drag = moveBar.parentNode;
  229. let disX = ev.clientX - Drag.offsetLeft;
  230. let disY = ev.clientY - Drag.offsetTop;
  231. document.onmousemove = (event) => {
  232. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  233. let ev = event || window.event;
  234. Drag.style.left = ev.clientX - disX + "px";
  235. Drag.style.top = ev.clientY - disY + "px";
  236. moveBar.style.cursor = "move";
  237. };
  238. document.onmouseup = (event) => {
  239. document.onmousemove = null;
  240. document.onmouseup = null;
  241. moveBar.style.cursor = "default";
  242. };
  243. },
  244. quickKeySetting: function() {
  245. this.quickKeyShow = true;
  246. this.floatMenuShow = false;
  247. this.otherShow = false;
  248. },
  249. floatMenuSetting: function() {
  250. this.quickKeyShow = false;
  251. this.floatMenuShow = true;
  252. this.otherShow = false;
  253. },
  254. otherSetting: function() {
  255. this.quickKeyShow = false;
  256. this.floatMenuShow = false;
  257. this.otherShow = true;
  258. },
  259. saveSettings: function() {
  260. var result = this.quickMsg.join("$");
  261. localStorage.quickMsg = result;
  262. for(let i=0;i<this.menuName.length;i++){
  263. if (this.menuName[i] == "") {
  264. this.menuName.splice(i, 1);
  265. this.menuName.splice(i, 1);
  266. }
  267. }
  268. var menuName = this.menuName.join("$");
  269. localStorage.menuName = menuName;
  270. var menuReason = this.menuReason.join("$");
  271. localStorage.menuReason = menuReason;
  272. if (this.reflashTime <= 0) {
  273. this.reflashTime = 0;
  274. this.tips = "定时刷新时间配置无效,将不会启用自动刷新功能。";
  275. this.timeOut = 3000;
  276. }
  277. if (this.reflashTime > 0 && this.reflashTime < 60) {
  278. this.reflashTime = 60;
  279. this.tips = "为了更好的操作体验,自动刷新时间不能低于60s!!!";
  280. this.timeOut = 3000;
  281. }
  282. if (this.globalChecked) {
  283. localStorage.removeItem(this.getUrlId());
  284. localStorage.reflashTime = this.reflashTime;
  285. } else {
  286. localStorage.setItem(this.getUrlId(), this.reflashTime);
  287. }
  288. localStorage.autoSend = this.autoSend;
  289. localStorage.autoRecord = this.autoRecord;
  290. localStorage.autoScroll = this.autoScroll;
  291. localStorage.autoCommitDel = this.autoCommitDel;
  292. localStorage.autoCommitDelTime = this.autoCommitDelTime >= minAutoTime ? this.autoCommitDelTime : minAutoTime;
  293. localStorage.autoCheckTime = this.autoCheckTime >= minAutoTime ? this.autoCheckTime : minAutoTime;
  294.  
  295. this.saveTips = "保存成功";
  296. setTimeout(() => {
  297. this.isShow = false;
  298. this.tips = "";
  299. this.saveTips = "保存";
  300. }, this.timeOut);
  301. },
  302. globalReload: function() {
  303. var reflashTime = localStorage.reflashTime;
  304. if (!reflashTime || isNaN(reflashTime) || reflashTime < 0) {
  305. reflashTime = 0;
  306. }
  307. this.globalChecked = true;
  308. this.currentChecked = false;
  309. this.reflashTime = reflashTime;
  310. },
  311. currentPageReload: function() {
  312. var currentReflashTime = localStorage.getItem(this.getUrlId());
  313. if (!currentReflashTime || isNaN(currentReflashTime) || currentReflashTime < 0) {
  314. currentReflashTime = 0;
  315. }
  316. this.globalChecked = false;
  317. this.currentChecked = true;
  318. this.reflashTime = currentReflashTime;
  319. },
  320. getUrlId: function() {
  321. var url = this.reloadTarget;
  322. if (!url || url.length <= 0) {
  323. return 0;
  324. }
  325. url = url.toLowerCase().replace("https://www.oneplusbbs.com/", "reload#");
  326. url = url.replace(".html", "#");
  327. return url;
  328. }
  329. }
  330. });
  331.  
  332. function appendConfirmDiv(){
  333. var confirmDiv = document.createElement("div");
  334. confirmDiv.innerHTML = '<div id="vue_confirm_div">'+
  335. '<div id="shadow_div" v-show="showConfirmDiv"></div>'+
  336. '<div id="confirm_div" v-show="showConfirmDiv">'+
  337. '<div>'+
  338. '<h2>是否执行删帖操作</h2>'+
  339. '<br><span class="confirm_span" @click="doDel">确认</span>'+
  340. '<span class="confirm_span" @click="cancelDel">取消</span>'+
  341. '<br><br><span class="confirm_span" @click="doDelAndOpen">确认&打开管理页面</span>'+
  342. '</div>'+
  343. '</div>'+
  344. '</div>';
  345. document.body.appendChild(confirmDiv);
  346. }
  347.  
  348. var confirmApp = new Vue({
  349. el: "#vue_confirm_div",
  350. data: {
  351. showConfirmDiv: false,
  352. doDelTag: 0,
  353. clickEle: null,
  354. targetHref: null
  355. },
  356. methods: {
  357. doDel: function() {
  358. this.showConfirmDiv = false;
  359. this.doDelTag = 1;
  360. this.handelDel();
  361. },
  362. cancelDel: function() {
  363. this.showConfirmDiv = false;
  364. this.doDelTag = 2;
  365. },
  366. doDelAndOpen: function() {
  367. this.showConfirmDiv = false;
  368. this.doDelTag = 3;
  369. this.handelDel();
  370. },
  371. handelDel: function() {
  372. if (this.doDelTag == 1 && this.clickEle != null) {
  373. this.clickEle.click();
  374. }else if (this.doDelTag == 3 && this.clickEle != null && this.targetHref != null) {
  375. this.clickEle.click();
  376. var open = document.createElement("a");
  377. open.href=this.targetHref;
  378. open.target="_blank";
  379. open.click();
  380. }
  381. defaultQuickPaste();
  382. return;
  383. }
  384. }
  385. });
  386. //悬浮菜单
  387. function appendFloatMenu(){
  388. var floatMenuDiv = document.createElement("div");
  389. floatMenuDiv.innerHTML = '<div id="float_menu">'+
  390. '<div class="fast_menu" @click="opFastMenu" style="background:#FFF;border-radius:3px;border:1px solid black;">{{opTip}}</div>'+
  391. '<div class="fast_menu" v-for = "item of (menuName == null ? 0 : menuName.length)" @click="handleFastMenu(item)">'+
  392. '{{menuName[item-1]}}</div>'+
  393. '</div>';
  394. document.body.appendChild(floatMenuDiv);
  395. var checkInterval = setInterval(function(){
  396. var check = document.querySelector("input[class='pc']:checked");
  397. if (check) {
  398. clearInterval(checkInterval);
  399. let mdly = $id("mdly");
  400. let left = mdly.getBoundingClientRect().left + 155;
  401. let top = mdly.getBoundingClientRect().top -3;
  402. $id("float_menu").style.left = left + "px";
  403. $id("float_menu").style.top = top + "px";
  404. }
  405. }, 350);
  406. }
  407.  
  408. var floatMenuApp = new Vue({
  409. el: "#float_menu",
  410. data: {
  411. menuName: getArrFromStorage("menuName", "$"),
  412. menuReason: getArrFromStorage("menuReason", "$"),
  413. autoCommitDel: parseBoolean(localStorage.autoCommitDel),
  414. autoCommitDelTime: localStorage.autoCommitDelTime,
  415. opOpen: true,
  416. opTip: "收起浮窗"
  417. },
  418. methods: {
  419. handleFastMenu: function(index) {
  420. var mdly = document.getElementById("mdly");
  421. if (mdly && mdly.style.display != "none") {
  422. recordScrollId();
  423. recordCount();
  424. var aList = mdly.getElementsByClassName("c")[0].getElementsByTagName("a");
  425. if (aList.length >= 3) {
  426. if (aList[2].innerHTML == "删除") {
  427. aList[2].click();
  428. let autoCheckTime = localStorage.autoCheckTime;
  429. if (!autoCheckTime && autoCheckTime < minAutoTime) {
  430. autoCheckTime = minAutoTime;
  431. }
  432. setTimeout(() => {
  433. var doc = quickPaste(0);
  434. if (doc) {
  435. autoChecked();
  436. doc.value = this.menuReason[index - 1];
  437. if (this.autoCommitDel) {
  438. this.autoCommitDelTime = this.autoCommitDelTime > minAutoTime ? this.autoCommitDelTime:minAutoTime;
  439. $id("modsubmit").innerHTML = this.autoCommitDelTime + "s自动提交";
  440. setTimeout(() => {
  441. $id("modsubmit").click();
  442. },this.autoCommitDelTime * unitTime);
  443. }
  444. };
  445. }, autoCheckTime * unitTime);
  446. }
  447. }
  448. } else {
  449. this.opTip = "请先勾选管理选项";
  450. setTimeout(() => {
  451. this.opTip = "收起浮窗";
  452. }, unitTime);
  453. }
  454. },
  455. opFastMenu: function() {
  456. if (this.opOpen) {
  457. this.opTip = "展开浮窗";
  458. this.menuName = [];
  459. } else {
  460. this.opTip = "收起浮窗";
  461. this.menuName = getArrFromStorage("menuName", "$");
  462. }
  463. this.opOpen = !this.opOpen;
  464. }
  465. }
  466. });
  467. function getQuickMsg() {
  468.  
  469. var msg = localStorage.quickMsg;
  470. if (!msg || null == msg || msg.split("$id").length == 0) {
  471. settingApp.isShow = true;
  472. settingApp.tips = "请先设置快捷键对应的内容";
  473. setTimeout(function() {
  474. settingApp.tips = "";
  475. }, 2000);
  476. return null;
  477. } else {
  478. return msg.split("$");
  479. }
  480. }
  481.  
  482. function getArrFromStorage(name,split){
  483. var storage = localStorage.getItem(name);
  484. if (!storage) {
  485. return null;
  486. }
  487. return storage.split(split);
  488. }
  489.  
  490. function pasteMsg(element, msgArr, id) {
  491. if (msgArr == null || msgArr.length < id) {
  492. settingApp.isShow = true;
  493. settingApp.tips = "当前快捷键暂未定义任何内容,请自定义后使用";
  494. settingApp.quickMsg = msgArr;
  495. setTimeout(function() {
  496. settingApp.tips = "";
  497. }, 2000);
  498. return;
  499. }
  500. if (element && msgArr.length >= id) {
  501. if (msgArr[id - 1] == "") {
  502. settingApp.isShow = true;
  503. settingApp.quickMsg = msgArr;
  504. settingApp.tips = "当前快捷键暂未定义任何内容,请自定义后使用";
  505. setTimeout(function() {
  506. settingApp.tips = "";
  507. }, 2000);
  508. return;
  509. }
  510. element.value = msgArr[id - 1];
  511. return;
  512. }
  513.  
  514. }
  515. //屏蔽默认快捷键
  516. function stopDefault(e) {
  517.  
  518. // W3C标准
  519. if (e.preventDefault) {
  520. e.preventDefault();
  521. } else {
  522. //IE
  523. window.event.returnValue = false;
  524. }
  525. return false;
  526. }
  527.  
  528. function defaultQuickPaste() {
  529. let autoCheckTime = localStorage.autoCheckTime;
  530. if (!autoCheckTime && autoCheckTime < minAutoTime) {
  531. autoCheckTime = minAutoTime;
  532. }
  533. setTimeout(function() {
  534. var doc = quickPaste(1);
  535. if (doc) {
  536. autoChecked();
  537. }
  538. }, autoCheckTime * unitTime);
  539. }
  540.  
  541. function quickPaste(id) {
  542.  
  543. var href = window.location.href;
  544. var quickMsg = getQuickMsg();
  545. //操作说明输入
  546. var mods = $id("fwin_mods");
  547. if (mods && mods.style.display != "none") {
  548. pasteMsg($id("reason"), quickMsg, id);
  549. return $id("reason");
  550. }
  551. //列表页
  552. var ftadmin = $id("floatlayout_topicadmin");
  553. if (ftadmin && ftadmin.style.display != "none") {
  554. pasteMsg($id("reason"), quickMsg, id);
  555. return $id("reason");
  556. }
  557. //回帖输入
  558. var reply = $id("fwin_reply");
  559. if (reply && reply.style.display != "none") {
  560. pasteMsg($id("postmessage"), quickMsg, id);
  561. return $id("postmessage");
  562. }
  563. //消息
  564. var showMsgBox = $id("fwin_showMsgBox");
  565. if (showMsgBox && showMsgBox.style.display != "none") {
  566. pasteMsg($id("pmmessage"), quickMsg, id);
  567. return $id("pmmessage");
  568. }
  569. //管理页面
  570. if (href.search("op=ban&uid=") != -1) {
  571. pasteMsg($id("ct").getElementsByClassName("pt")[0], quickMsg, id);
  572. }
  573. }
  574.  
  575. //判断是否已显示操作选项
  576. var cateShow = false;
  577. //分类选项索引
  578. var cateIndex = 0;
  579.  
  580. //移动操作
  581. var moveShow = false;
  582. //游乐园
  583. var moveIndex = 21;
  584.  
  585. function handlePost(e) {
  586.  
  587. // Ctrl + z 快速回复
  588. if (e.keyCode == 90 && e.ctrlKey) {
  589. stopDefault(e);
  590. $id("post_reply").click();
  591. defaultQuickPaste();
  592. return;
  593. }
  594.  
  595. //获取操作列表
  596. var modMenu = $id("modmenu");
  597. if (!modMenu) {
  598. console.log("当前板块无权限");
  599. return;
  600. }
  601. var links = modMenu.getElementsByTagName("a");
  602. //Ctrl+D 快速删除
  603. if (e.keyCode == 68 && e.ctrlKey) {
  604. stopDefault(e);
  605. var mdly = $id("mdly");
  606. if (mdly && mdly.style.display != "none") {
  607. recordScrollId();
  608. var aList = mdly.getElementsByClassName("c")[0].getElementsByTagName("a");
  609. if (aList.length >= 3) {
  610. if (aList[2].innerHTML == "删除") {
  611. aList[2].click();
  612. }
  613. }
  614. defaultQuickPaste();
  615. return;
  616. } else {
  617. //增加二次确认
  618. confirmApp.showConfirmDiv = true;
  619. confirmApp.clickEle = links[0];
  620. let user_url = $class("authi xg1 xs2")[0].getElementsByTagName("a")[0].href;
  621. let uid = user_url.replace(/https:\/\/www.oneplusbbs.com\/homemod-space-uid-/g, "").replace(/.html/g, "");
  622. confirmApp.targetHref = "https://www.oneplusbbs.com/forum.php?mod=modcp&action=member&op=ban&uid=" + uid;
  623. }
  624. }
  625. //Ctrl+Alt 快速分类功能
  626. if (e.altKey && e.ctrlKey) {
  627. stopDefault(e);
  628. quickCate(links[10]);
  629. return;
  630. }
  631. //Ctrl+X 快速移动功能
  632. if (e.ctrlKey && e.keyCode == 88) {
  633. stopDefault(e);
  634. quickMove(links[9]);
  635. return;
  636. }
  637. resetCateAndMove();
  638. }
  639.  
  640. function handleList(e) {
  641. var checkBoxs = document.getElementsByClassName("o");
  642. if (!checkBoxs || checkBoxs.length < 5) {
  643. console.log("此版块无权限");
  644. }
  645. var mdly = $id("mdly");
  646. if (mdly) {
  647. var ops = mdly.getElementsByTagName("p")[0].getElementsByTagName("a");
  648. if (!ops || ops.length < 3) {
  649. return;
  650. }
  651. // ctrl + alt
  652. if (e.altKey && e.ctrlKey) {
  653. stopDefault(e);
  654. quickCate(ops[2]);
  655. return;
  656. }
  657. // ctrl + x
  658. if (e.ctrlKey && e.keyCode == 88) {
  659. stopDefault(e);
  660. quickMove(ops[1]);
  661. return;
  662. }
  663. // ctrl + d
  664. if (e.keyCode == 68 && e.ctrlKey) {
  665. stopDefault(e);
  666. ops[0].click();
  667. defaultQuickPaste();
  668. return;
  669. }
  670. resetCateAndMove();
  671. }
  672. }
  673.  
  674. //自动刷新
  675. function autoReflash() {
  676. var reflashTime = 0;
  677. var url = window.location.href;
  678. if (!url || url.length <= 0) {
  679. return 0;
  680. }
  681. url = url.toLowerCase().replace("https://www.oneplusbbs.com/", "reload#");
  682. url = url.replace(".html", "#");
  683. var currentReflashTime = parseInt(localStorage.getItem(url));
  684. if (!isNaN(currentReflashTime)) {
  685. reflashTime = currentReflashTime;
  686. } else {
  687. if (!localStorage.reflashTime) {
  688. reflashTime = 0;
  689. } else {
  690. reflashTime = parseInt(localStorage.getItem("reflashTime"));
  691. }
  692. }
  693.  
  694. if (isNaN(reflashTime) || reflashTime <= 0) {
  695. return;
  696. }
  697. var title = document.title;
  698. var loopInterval = setInterval(function() {
  699. document.title = "【" + formatTime(reflashTime) + "】" + title;
  700. if (reflashTime === 0) {
  701. clearInterval(loopInterval);
  702. location.reload();
  703. return;
  704. }
  705. reflashTime--;
  706. }, 1000);
  707. }
  708.  
  709. function formatTime(t) {
  710. if (isNaN(t)) return "";
  711. var s = "";
  712. var h = parseInt(t / 3600);
  713. s += (pad(h) + ":");
  714. t -= (3600 * h);
  715. var m = parseInt(t / 60);
  716. s += (pad(m) + ":");
  717. t -= (60 * m);
  718. s += pad(t);
  719. return s;
  720. }
  721.  
  722. function pad(n) {
  723. return ("00" + n).slice(-2);
  724. }
  725.  
  726. function autoChecked() {
  727. document.getElementById("crimerecord").checked = parseBoolean(localStorage.autoRecord);
  728. document.getElementById("sendreasonpm").checked = parseBoolean(localStorage.autoSend);
  729. }
  730. //快捷点击分类链接
  731. function quickCate(ele) {
  732. if (!cateShow) {
  733. if (ele) {
  734. ele.click();
  735. cateShow = true;
  736. }
  737. } else {
  738. let types = $id("typeid");
  739. if (types && types.options.length > 0) {
  740. types.size = 9;
  741. types.onclick = function() {
  742. types.size = 1;
  743. };
  744. types.options[cateIndex].selected = "true";
  745. cateIndex++;
  746. }
  747. if (cateIndex == types.options.length) {
  748. cateIndex = 0;
  749. }
  750. }
  751. }
  752. //快捷点击移动链接
  753. function quickMove(ele) {
  754. if (!moveShow) {
  755. if (ele) {
  756. ele.click();
  757. moveShow = true;
  758. }
  759. } else {
  760. var moveTo = $id("moveto");
  761. if (moveTo && moveTo.options.length > 0) {
  762. moveTo.size = 9;
  763. moveTo.onclick = function() {
  764. moveTo.size = 1;
  765. }
  766. moveTo.options[moveIndex].selected = "true";
  767. moveTo.onchange();
  768. //游乐园 <--> 轻摄影
  769. moveIndex = moveIndex == 21 ? 13 : 21;
  770. }
  771.  
  772. }
  773. }
  774. //重置
  775. function resetCateAndMove() {
  776. moveIndex = 21;
  777. cateIndex = 0;
  778. moveShow = false;
  779. cateShow = false;
  780. }
  781. function recordScrollId(){
  782. var threadId = getThreadId();
  783. if (threadId == null) {
  784. alert("处理自动定位失败,请记录当前连接,联系作者反馈");
  785. return;
  786. }
  787. var checkId = document.querySelector("input[class='pc']:checked").value;
  788. var nextCheckId = $id("post_" + checkId).previousSibling.id;
  789. sessionStorage.setItem(threadId, nextCheckId);
  790. }
  791.  
  792. function recordCount(){
  793. var count = sessionStorage.count;
  794. if (!count) {
  795. count = 0;
  796. }
  797. count = (++count) % 100;
  798. unitTime = unitTime + count * 5;
  799. sessionStorage.count = count;
  800. }
  801. //自动定位到上次操作位置
  802. function autoScroll(){
  803. if (parseBoolean(localStorage.autoScroll)) {
  804. var threadId = getThreadId();
  805. if (threadId != null) {
  806. var doc_id = sessionStorage.getItem(threadId);
  807. if (doc_id) {
  808. if (!$id(doc_id)) {
  809. sessionStorage.removeItem(threadId);
  810. return;
  811. }
  812. $id(doc_id).nextSibling.scrollIntoView({
  813. behavior: "smooth",block: "center"
  814. });
  815. }
  816. }
  817. }
  818. }
  819. //获取帖子id
  820. function getThreadId(){
  821. var url = window.location.href;
  822. var index = url.indexOf("thread-");
  823. if (index>=0) {
  824. index += 7;
  825. }else {
  826. index = url.indexOf("tid=");
  827. if (index >= 0) {
  828. index += 4;
  829. }
  830. }
  831. if (index >= 0) {
  832. return url.substring(index, index + 7);
  833. }
  834. return null;
  835. }
  836.  
  837. function parseBoolean(item){
  838. if (!item) {
  839. return false;
  840. }
  841. var result = false;
  842. try {
  843. result = JSON.parse(item);
  844. } catch(e) {
  845. console.log("配置转换失败");
  846. }
  847. return result;
  848. }