Greasy Fork 还支持 简体中文。

TC Revive Check

description

  1. // ==UserScript==
  2. // @name TC Revive Check
  3. // @namespace namespace
  4. // @version 0.1
  5. // @description description
  6. // @license MIT
  7. // @author tos
  8. // @match *.torn.com/factions.php*
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. const APIKEY = 'API_KEY_HERE'
  13.  
  14. GM_addStyle(`
  15. #x_revive_check {
  16. background-color: #3675eb;
  17. border-radius: 0.5em;
  18. color: #eee;
  19. cursor: pointer;
  20. display: flex;
  21. font-weight: bold;
  22. margin: 1em;
  23. padding: 0.5em;
  24. position: absolute;
  25. right: 0em;
  26. top: 8em;
  27. }
  28.  
  29. .x_revivable {
  30. background-color: #66b7ee;
  31. }
  32. `)
  33.  
  34. document.querySelector('BODY').insertAdjacentHTML('afterbegin', `<div id="x_revive_check">Revivable?</div>`)
  35. const revive_check_button = document.querySelector('#x_revive_check')
  36. revive_check_button.addEventListener('click', (e) => {
  37. revive_check_button.innerText = 'Working...'
  38. const profile_links = document.querySelectorAll('LI.table-row [href*="/profiles.php?XID="]')
  39. const profile_fetches = Array.from(profile_links).map((link) => {
  40. const playerID = link.href.split('=')[1]
  41. return fetch(`https://api.torn.com/user/${playerID}?selections=profile&key=${APIKEY}`)
  42. .then(r => r.json())
  43. .then((res) => {
  44. if (res.revivable == 1) link.closest('LI.table-row').classList.add('x_revivable')
  45. else if (res.error) {
  46. revive_check_button.innerText = 'API ERROR'
  47. throw res.error.error
  48. }
  49. })
  50. .catch(console.error)
  51. })
  52. Promise.all(profile_fetches)
  53. .then(f => revive_check_button.innerText = 'Complete')
  54. .catch(console.error)
  55. })