OnePlusBBS QuickKey

一加社区快捷键

当前为 2020-05-01 提交的版本,查看 最新版本

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