Last active
October 8, 2020 11:50
-
-
Save bert-w/c92b925224e1050770bc652ae922539c to your computer and use it in GitHub Desktop.
BrickLinkMod
This file contains hidden or 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 BrickLinkMod | |
// @description Mark sets you own on bricklink.com interface | |
// @author BertW | |
// @version 1.0.1 | |
// @require https://code.jquery.com/jquery-3.5.1.slim.min.js | |
// @grant none | |
// @match https://www.bricklink.com/* | |
// ==/UserScript== | |
console.log('[BrickLinkMod] Start'); | |
var VERSION = '1.0.1'; | |
/////////////////////////////////////////////////////////////////////// | |
//// OPTIONS | |
/////////////////////////////////////////////////////////////////////// | |
var OWNED = []; | |
var COLOR = '#eeca06'; | |
var HIDE_OTHERS = true; | |
var REMOVE_OTHERS = false; | |
/////////////////////////////////////////////////////////////////////// | |
//// END OPTIONS | |
/////////////////////////////////////////////////////////////////////// | |
function toggleStyle() { | |
var $style = $('style#bricklinkmod-style'); | |
if ($style.length) { | |
return $style.remove(); | |
} | |
$('body').append(`<style id="bricklinkmod-style"> | |
.bricklinkmod-owned { | |
background: ${COLOR} !important; | |
} | |
.bricklinkmod-not-owned { | |
opacity: 0.5; | |
${REMOVE_OTHERS ? 'display: none;' : ''} | |
} | |
</style>`); | |
} | |
function tag() { | |
$('table#id-main-legacy-table td[nowrap] a:first-of-type').each(function () { | |
var $tr = $(this).closest('tr'); | |
if (OWNED.indexOf(this.innerHTML) >= 0) { | |
$tr.addClass('bricklinkmod-owned').removeClass('bricklinkmod-not-owned'); | |
} else { | |
$tr.addClass('bricklinkmod-not-owned').removeClass('bricklinkmod-owned'); | |
} | |
}); | |
} | |
var $panel = $($.parseHTML(` | |
<div id="bricklinkmod-panel" style="position: fixed; bottom: 5px; left: 5px; padding: 5px; background: rgba(0,0,0,0.3);"> | |
<code style="font-size: 1rem">BrickLink Mod ${VERSION}</code><br /> | |
<button>Toggle</button> | |
<input type="text" value="${localStorage.getItem('bricklinkmod-owned') || ''}" placeholder="Comma-separated codes" /> | |
</div> | |
`)); | |
$('body').append($panel); | |
$('#bricklinkmod-panel button').on('click', function () { | |
toggleStyle(); | |
console.log('[BrickLinkMod] Toggle'); | |
}); | |
$('#bricklinkmod-panel input').on('change', function () { | |
OWNED = $(this).val().replace(/\s+/g, '').split(','); | |
localStorage.setItem('bricklinkmod-owned', $(this).val()); | |
tag(); | |
console.log('[BrickLinkMod] Tag'); | |
}).change(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment