Last active
May 15, 2024 17:40
-
-
Save iamevn/3afea03de61fa351bcde666f7c6d13f6 to your computer and use it in GitHub Desktop.
simple userscript to insert download links back into cdromance (you might need to refresh the page if the links break) (click raw link near top right to install)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name CDR insert links | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-02-12_v3 | |
// @description inject external download links on cdromance | |
// @author iamevn | |
// @match https://cdromance.com/* | |
// @grant GM.xmlHttpRequest | |
// @connect cdromance.org | |
// @updateURL http://gist.github.com/iamevn/3afea03de61fa351bcde666f7c6d13f6/raw/cdromance-download-links.user.js | |
// @downloadURL http://gist.github.com/iamevn/3afea03de61fa351bcde666f7c6d13f6/raw/cdromance-download-links.user.js | |
// ==/UserScript== | |
// TODO: grab cdr_ticket from api | |
// TODO: automatically add links instead of requiring a button press | |
(function() { | |
'use strict'; | |
const ids = { | |
style: 'downloadStyle', | |
details: 'downloadDetails', | |
queryButton: 'downloadQuery', | |
}; | |
const addStyle = () => { | |
const styleText = ` | |
<style id="${ids.style}"> | |
#${ids.details} > summary { | |
display: list-item; | |
} | |
/* taken from cdromance.org's style */ | |
.download-links.table { | |
display: table; | |
width: 100%; | |
border-collapse: collapse; | |
background-color: #2a2a2a; /* Dark shade for tables */ | |
color: #c0c0c0; /* Light grey text for readability */ | |
font-family: sans-serif; | |
} | |
.download-links .tr { display: table-row } | |
.download-links .th, .td { | |
display: table-cell; | |
border: 1px solid #3f3f3f; | |
padding: 5px; | |
height: 25px; | |
vertical-align: middle; | |
text-align: center; | |
color: #d9d9d9; | |
} | |
.download-links a { | |
color: #4fc3f7; /* Bright color for links to stand out */ | |
} | |
.download-links a:visited { | |
color: #b085f5; /* Distinguish visited links with a different shade */ | |
} | |
</style>`; | |
if (!document.getElementById(ids.style)) { | |
document.head.insertAdjacentHTML('beforeend', styleText); | |
}; | |
}; | |
const spanHasTicket = (ticketSpan) => !!ticketSpan.innerText.match(/^\d+$/); | |
const getDownloads = (ticketTd, ticketSpan) => { | |
const onTicketResponse = (response) => { | |
const parser = new DOMParser(); | |
const resHtml = parser.parseFromString(response.responseText, 'text/html'); | |
console.debug(resHtml); | |
const resContent = resHtml.querySelector('#contentArea'); | |
if (resContent) { | |
console.debug(resContent.outerHTML); | |
if (document.getElementById(ids.details)) { | |
const details = document.getElementById(ids.details); | |
details.innerHTML = resContent.outerHTML; | |
details.insertAdjacentHTML('afterbegin', '<summary>External Links</summary>'); | |
} else { | |
addStyle(); | |
// add open details with the table and add the style | |
const details = document.createElement('details') | |
details.id = ids.details; | |
details.toggleAttribute('open', true); | |
details.innerHTML = resContent.outerHTML; | |
details.insertAdjacentHTML('afterbegin', '<summary>External Links</summary>'); | |
ticketTd.appendChild(details); | |
} | |
} | |
}; | |
if (spanHasTicket(ticketSpan)) { | |
const ticket = ticketSpan.innerText; | |
console.debug('ticket', ticket); | |
GM.xmlHttpRequest({ | |
data: `cdrTicketInput=${ticket}`, | |
method: 'POST', | |
responseType: 'document', | |
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | |
url: 'https://cdromance.org', | |
onload: onTicketResponse, | |
}); | |
} | |
}; | |
const addButton = (ticketTd, ticketSpan) => { | |
if (document.getElementById(ids.queryButton)) { | |
return document.getElementById(ids.queryButton); | |
} else { | |
const input = document.createElement('input'); | |
input.id = ids.queryButton; | |
input.type = 'button'; | |
input.value = 'Find downloads'; | |
input.onclick = () => getDownloads(ticketTd, ticketSpan); | |
ticketTd.appendChild(input); | |
return input; | |
} | |
}; | |
const ticketTd = document.querySelector('table td:has(span#obfuscatedId)'); | |
if (ticketTd) { | |
const ticketSpan = ticketTd.querySelector('span#obfuscatedId'); | |
if (ticketSpan) { | |
addButton(ticketTd, ticketSpan); | |
} | |
} | |
})(); |
Working good thank you
I can't find any "CDR-ticket" tab on the site, not even in the source code. The script isn't working either.
@ThunderMite42 the button has moved, look for "find links" near the bottom
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I saw the solution searching in google. Thank you!