Skip to content

Instantly share code, notes, and snippets.

@Dinir
Last active May 31, 2019 21:03
Show Gist options
  • Save Dinir/023cebc82d20cc06d0a790acf374d337 to your computer and use it in GitHub Desktop.
Save Dinir/023cebc82d20cc06d0a790acf374d337 to your computer and use it in GitHub Desktop.
Loads a custom skin to Jstris, a userscript for Tampermonkey.
// ==UserScript==
// @name Jstris Custom Skin Loader
// @namespace http://tampermonkey.net/
// @downloadURL https://gist.githubusercontent.com/Dinir/023cebc82d20cc06d0a790acf374d337/raw/3c7377b2948201a41090deddf1d6972bc131acba/Jstris-loadCustomSkin.user.js
// @version 1.2
// @match https://*.jstris.jezevec10.com/*
// @grant none
// @run-at document-end
// @description Loads a custom skin to Jstris.
// @author Dinir Nertan
// @homepage https://dinir.works
// @icon https://i.imgur.com/FKXEPIn.png
// ==/UserScript==
// Run this script at 'document-end'. You can set it in 'Settings' tab next to 'Editor'.
(function () {
'use strict'
// store other skins in this manner: `name: ['address', size],`.
const favSkins = {
mf: ['https://i.imgur.com/t29rjjK.png', 24],
bs48: ['https://i.imgur.com/8Fo3afG.png', 32],
}
// Define paths for your custom skin here.
const customSkinPath = {
bgImage: null,
bgColor: null,
bgColorHeight: '1000px',
// type either `favSkins.name` or `['address', size]`.
blockSkinAndSize: favSkins.bs48,
ghostBlockSkinAndSize: [null, null]
}
const isArrayAndHasItem = instance =>
Array.isArray(instance) && instance.some(v => v !== null)
const loadCustomSkin = () => {
if (customSkinPath.bgImage) {
document.body.style.backgroundImage = `url(${customSkinPath.bgImage})`
document.body.style.backgroundSize = '100%'
}
if (customSkinPath.bgColor) {
document.getElementById("app").style.backgroundColor = customSkinPath.bgColor
document.getElementById("app").style.height = customSkinPath.bgColorHeight
}
// if (typeof loadSkin !== 'undefined') {
if (isArrayAndHasItem(customSkinPath.blockSkinAndSize)) {
loadSkin(customSkinPath.blockSkinAndSize[0], customSkinPath.blockSkinAndSize[1])
}
if (isArrayAndHasItem(customSkinPath.ghostBlockSkinAndSize)) {
loadGhostSkin(
customSkinPath.ghostBlockSkinAndSize[0],
customSkinPath.ghostBlockSkinAndSize[1] ?
customSkinPath.ghostBlockSkinAndSize[1] :
customSkinPath.blockSkinAndSize[1]
)
}
// }
}
window.addEventListener('load', loadCustomSkin)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment