Replace IGDB with cs.rin.ru for Backloggd

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

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

// ==UserScript==
// @name        Replace IGDB with cs.rin.ru for Backloggd
// @description Replaces the IGDB button on Backloggd with a cs.rin.ru downolad link
// @author      Soap
// @namespace   soap.systems
// @homepageURL https://soap.systems
// @match       *://backloggd.com/*
// @match       *://*.backloggd.com/*
// @grant       none
// @version     1.2
// @icon        https://external-content.duckduckgo.com/ip3/www.backloggd.com.ico
// @license     GPLv3
// ==/UserScript==

/*
    TODO:
    - currently the script takes you to the search results. update it to check the results page, and if there's only one match result, open it automatically
        - maybe i could add a url parameter to the links opened by the script to make sure it doesn't interfere with normal use of the site
    - add a ProtonDB button if the "released on" section doesn't include Linux
    - scrape the IGDB link to add a gog-games.to link if it exists
    - SteamRip link? Might be kinda redundant
*/

// We have to get the game name and the right element from the IGDB link because Backloggd doesn't have any meaningful class names

function changeIgdbUrl () {
  const link = document.querySelector('a[href^="https://www.igdb.com/games/"]')
  const linkElement = link.parentElement

  if (linkElement) {
    let searchURL = getSearchUrl(link)
    linkElement.innerHTML = `Download on <a href="${searchURL}" target="_blank">cs.rin.ru</a>`
  }
}


function getSearchUrl(link) {
  // examle IGDB link: https://backloggd.com/games/yakuza-6-the-song-of-life
  let searchQuery = link.href.split('/').pop()
  searchQuery = searchQuery.replaceAll('-', ' ')
  searchQuery = encodeURIComponent(searchQuery)
  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'
  return searchURL
}

// Backloggd uses those weird SPA style links, so we have to re-run each time the url changes
// Will occasionally decide to not work. Refresh fixes this but might be worth migrating to vm-url in case that works better
// https://violentmonkey.github.io/api/matching/#matching-spa-sites-like-fb-github-twitter-youtube

onUrlChange();

if (self.navigation) {
  navigation.addEventListener('navigatesuccess', onUrlChange);
} else {
  let u = location.href;
  new MutationObserver(() => u !== (u = location.href) && onUrlChange())
    .observe(document, {subtree: true, childList: true});
}

function onUrlChange() {
  changeIgdbUrl()
}