select plus account

方便选取plus共享账号

  1. // ==UserScript==
  2. // @name select plus account
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 方便选取plus共享账号
  6. // @author You
  7. // @match https://*.zhile.io/shared.html
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=zhile.io
  9. // @grant none
  10. // @license MIT License
  11. // @run-at document-idle
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Your code here...
  18. let accountNodes
  19. let try_max = 100
  20. let try_times = 0
  21. const func = () => {
  22. try_times++
  23. accountNodes = document.querySelectorAll(".account-list .plus");
  24. if (accountNodes==null && try_times < try_max) {
  25. setTimeout(func, 100)
  26. }
  27. }
  28. const div = document.createElement('div')
  29. div.style = "position: fixed;top: 20px;left: 20px;"
  30. const btnUp = document.createElement('button')
  31. const btnDown = document.createElement('button')
  32. const btnFirst = document.createElement('button')
  33. const btnLast = document.createElement('button')
  34. btnUp.innerText = '<'
  35. btnDown.innerText = '>'
  36. btnFirst.innerText = '|<'
  37. btnLast.innerText = '>|'
  38. let selectIndex = 0;
  39. const fnClick = (op) => () => {
  40. if(accountNodes == null) {
  41. func()
  42. }
  43. if(accountNodes == null) {
  44. console.log("accountNodes get fail")
  45. return
  46. }
  47. if("first" === op) {
  48. selectIndex = 0
  49. } else if("up" === op && selectIndex > 0) {
  50. selectIndex--
  51. } else if("last" === op) {
  52. selectIndex = accountNodes.length - 1
  53. } else if("down" === op && selectIndex < accountNodes.length - 1) {
  54. selectIndex++
  55. }
  56. const account = accountNodes[selectIndex];
  57. if(account == null) {
  58. console.log("account get fail")
  59. return
  60. }
  61. scrollTo(0, selectIndex > accountNodes.length / 2 ? account.offsetTop + account.offsetHeight + 20
  62. : account.offsetTop - 20)
  63. }
  64. btnUp.onclick = fnClick("up")
  65. btnDown.onclick = fnClick("down")
  66. btnFirst.onclick = fnClick("first")
  67. btnLast.onclick = fnClick("last")
  68. div.appendChild(btnFirst)
  69. div.appendChild(btnUp)
  70. div.appendChild(btnDown)
  71. div.appendChild(btnLast)
  72. document.body.appendChild(div)
  73. })();