Replace IGDB with cs.rin.ru for Backloggd

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

Versión del día 11/3/2025. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==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/*
// @match       *://cs.rin.ru/forum/search.php*
// @grant       none
// @version     1.5
// @icon        https://external-content.duckduckgo.com/ip3/www.backloggd.com.ico
// @license     GPLv3
// ==/UserScript==


// OPTIONS:
// disable turbolinks-style navigation. this might make the site feel slower (though, not any slower than a normal website)
// but it fixes an issue where links sometimes won't change automatically without a refresh
// DEFAULT: true
const disableTurbolinks = true
// note that when the script updates you will have to reconfigure any options. shouldn't update too often though.

/*
    TODO:
    - would be nice to replace the variable-based config with a key/value type deal with GM_setValue
    - 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
*/

function removeTurbolinks() {
  if (location.host == 'backloggd.com') {
    document.querySelectorAll('a').forEach(link => {
      if (link.href.startsWith('https://backloggd.com')) {
        link.setAttribute('data-turbolinks', 'false');
      }
    });
  }
}

// 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 () {
  if (location.host == 'backloggd.com') {
    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&backloggdrinscript=true'
  return searchURL
}

function clickFirstRinLink() {
  let params = new URLSearchParams(document.location.search)
  // There's a 'backloggdrinscript' parameter added to the end of the search URL so we can detect you got to the search page from the script
  let scriptActive = params.get('backloggdrinscript');
  if (scriptActive) {
    const topics = document.querySelectorAll('a.topictitle');

    // only redirect if there's one link in the search results
    if (topics.length === 1) {
        window.location.href = topics[0].href;
    }
  }
}

if (disableTurbolinks === true) {
  removeTurbolinks()
}

clickFirstRinLink()


// Backloggd uses turbolinks, so we have to re-run each time the url changes
// Will occasionally decide to not work. Refreshing 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 && disableTurbolinks === false) {
  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()
}