Replace IGDB with cs.rin.ru for Backloggd

Replaces the IGDB button on Backloggd with a cs.rin.ru downolad link

目前為 2025-03-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Replace IGDB with cs.rin.ru for Backloggd
  3. // @description Replaces the IGDB button on Backloggd with a cs.rin.ru downolad link
  4. // @author Soap
  5. // @namespace soap.systems
  6. // @homepageURL https://soap.systems
  7. // @match *://backloggd.com/*
  8. // @match *://*.backloggd.com/*
  9. // @match *://cs.rin.ru/forum/search.php*
  10. // @grant GM_registerMenuCommand
  11. // @version 1.7
  12. // @icon https://external-content.duckduckgo.com/ip3/www.backloggd.com.ico
  13. // @license GPLv3
  14. // ==/UserScript==
  15.  
  16.  
  17. // OPTIONS:
  18. // disable turbolinks-style navigation. this might make the site feel slower (though, not any slower than a normal website)
  19. // but it fixes an issue where links sometimes won't change automatically without a refresh
  20. // DEFAULT: true
  21. const disableTurbolinks = true
  22. // even with disableTurbolinks, results from searches will still open with turbolinks navigation
  23. // this adds a right click option on Tampermonkey and an extension menu option on Violentmonky
  24. // which will manually update the link
  25. // DEFAULT: true
  26. const enableContextMenu = true
  27. // note that when the script updates you will have to reconfigure any options. shouldn't update too often though.
  28.  
  29. /*
  30. TODO:
  31. - would be nice to replace the variable-based config with a key/value type deal with GM_setValue
  32. - add a ProtonDB button if the "released on" section doesn't include Linux
  33. - scrape the IGDB link to add a gog-games.to link if it exists
  34. - SteamRip link? Might be kinda redundant
  35. */
  36.  
  37. function removeTurbolinks() {
  38. if (location.host == 'backloggd.com') {
  39. document.querySelectorAll('a').forEach(link => {
  40. if (link.href.startsWith('https://backloggd.com')) {
  41. link.setAttribute('data-turbolinks', 'false');
  42. }
  43. });
  44. }
  45. }
  46.  
  47. // We have to get the game name and the right element from the IGDB link because Backloggd doesn't have any meaningful class names
  48. function changeIgdbUrl () {
  49. if (location.host == 'backloggd.com') {
  50. const link = document.querySelector('a[href^="https://www.igdb.com/games/"]')
  51. const linkElement = link.parentElement
  52.  
  53. if (linkElement) {
  54. let searchURL = getSearchUrl(link)
  55. linkElement.innerHTML = `Download on <a href="${searchURL}" target="_blank">cs.rin.ru</a>`
  56. }
  57. }
  58. }
  59.  
  60.  
  61. function getSearchUrl(link) {
  62. // examle IGDB link: https://backloggd.com/games/yakuza-6-the-song-of-life
  63. let searchQuery = link.href.split('/').pop()
  64. searchQuery = searchQuery.replaceAll('-', ' ')
  65. let searchURL = 'https://cs.rin.ru/forum/search.php?keywords=' + searchQuery + '&terms=all&author=&sc=1&sf=titleonly&sk=t&sd=d&sr=topics&st=0&ch=300&t=0&submit=Search&backloggdrinscript=true'
  66. return searchURL
  67. }
  68.  
  69. function clickFirstRinLink() {
  70. let params = new URLSearchParams(document.location.search)
  71. // There's a 'backloggdrinscript' parameter added to the end of the search URL so we can detect that you got to the search page from the script
  72. let scriptActive = params.get('backloggdrinscript');
  73. if (scriptActive) {
  74. const topics = document.querySelectorAll('a.topictitle');
  75.  
  76. // only redirect if there's one link in the search results
  77. if (topics.length === 1) {
  78. window.location.href = topics[0].href;
  79. }
  80. }
  81. }
  82.  
  83. if (disableTurbolinks === true) {
  84. removeTurbolinks()
  85. }
  86.  
  87. clickFirstRinLink()
  88.  
  89. if (enableContextMenu === true) {
  90. GM_registerMenuCommand('Replace URL', changeIgdbUrl)
  91. }
  92.  
  93. // Backloggd uses turbolinks, so we have to re-run each time the url changes
  94. // Will occasionally decide to not work. Refreshing fixes this but might be worth migrating to vm-url in case that works better
  95. // https://violentmonkey.github.io/api/matching/#matching-spa-sites-like-fb-github-twitter-youtube
  96. onUrlChange()
  97.  
  98. if (self.navigation && disableTurbolinks === false) {
  99. navigation.addEventListener('navigatesuccess', onUrlChange);
  100. } else {
  101. let u = location.href;
  102. new MutationObserver(() => u !== (u = location.href) && onUrlChange())
  103. .observe(document, {subtree: true, childList: true});
  104. }
  105.  
  106. function onUrlChange() {
  107. changeIgdbUrl()
  108. }