Skip to content

Instantly share code, notes, and snippets.

@q00u
Last active May 25, 2017 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save q00u/bb6bcc9bfe9ee9b381e60851442eff66 to your computer and use it in GitHub Desktop.
Save q00u/bb6bcc9bfe9ee9b381e60851442eff66 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name StarGiveaways
// @namespace StarGiveaways
// @description ONLY adds the ability to see ESGST giveaways.
// @version 0.0.1
// @author revilheart
// @contributor Royalgamer06
// @contributor q00u
// @match https://www.steamgifts.com/*
// @match https://www.steamtrades.com/*
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @noframes
// ==/UserScript==
try {
var matches = document.querySelectorAll(`[href^="ESGST-"]`);
var n = matches.length;
if (n > 0) {
for (var i = 0; i < n; ++i) {
var code = matches[i].getAttribute(`href`).match(/ESGST-(.+)/)[1];
var decodedCode = decodeGiveawayCode(code);
var html = `<a href="/giveaway/${decodedCode}/">/giveaway/${decodedCode}/</a><br/>`;
var actions = matches[i].closest(`.comment`).getElementsByClassName(`comment__actions`)[0];
html = `
<a class="esgst-eg" href="/giveaway/${decodedCode}/" title="ESGST Exclusive Giveaway">
<i class="fa fa-spin fa-star"></i>
</a>
`;
actions.insertAdjacentHTML(`beforeEnd`, html);
}
}
} catch (error) {
console.log(error);
window.alert(`StarGiveaways has failed to load. Check the console for more info.`);
}
function decodeGiveawayCode(code) {
var decodedCode = ``;
var separatedCode = code.split(`-`);
for (var i = 0, n = separatedCode.length; i < n; ++i) {
decodedCode += String.fromCharCode(parseInt(separatedCode[i], 16));
}
return rot(decodedCode, 13);
}
function rot(string, n) {
return string.replace(/[a-zA-Z]/g, function (char) {
return String.fromCharCode(((char <= `Z`) ? 90 : 122) >= ((char = char.charCodeAt(0) + n)) ? char : (char - 26));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment