-
-
Save iamevn/3afea03de61fa351bcde666f7c6d13f6 to your computer and use it in GitHub Desktop.
// ==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); | |
} | |
} | |
})(); |
tysm
Iamevn would you dm spike on CDRomance discord pls?
Hi! I install it, refresh the page, restart chrome... but it doesn´t work. Am I doing something wrong? Thank you.
Hi! I install it, refresh the page, restart chrome... but it doesn´t work. Am I doing something wrong? Thank you.
The download option comes in the "CDR_TICKET" tab, not in the space where it used to be. Have you checked it there?
Hi! Thanks. I can see a number in the tab “CDR_ticket”, below the tab “console”, but it isn’t a link, just a number. Could you send me a PM explaining what to do? Many thanks!
Hi! Thanks. I can see a number in the tab “CDR_ticket”, below the tab “console”, but it isn’t a link, just a number. Could you send me a PM explaining what to do? Many thanks!
It's not supposed to be a link. I suggest you join CDRomance discord and read #how-to-download.
The discord invite appears when you load comments for any game in cdromance site (On top of them).
not working on chrome
edit works i had tamper disabled
I saw the solution searching in google. Thank you!
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
install steps: