Last active
February 12, 2018 19:00
-
-
Save yanorei32/08a5d10bea155200e6cdf3340f4fa4f3 to your computer and use it in GitHub Desktop.
Added function to show BRG value to w3schools colors RGB
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 Append BRG Value | |
// @namespace http://tyan0.dip.jp/~rei/ | |
// @version 1.0 | |
// @description Added function to show BRG value to w3schools colors RGB | |
// @author yanorei32 | |
// @match https://www.w3schools.com/colors/colors_rgb.asp | |
// @grant none | |
// ==/UserScript== | |
// 以下のリンクからダウンロードすると、アップデートチェックしてくれるっぽいです | |
// https://gist.github.com/Yanorei32/08a5d10bea155200e6cdf3340f4fa4f3/raw/append_brg_value.user.js | |
;(function() { | |
'use strict'; | |
let main = document.getElementById('main'); | |
let container = main.querySelector('.w3-container.w3-padding-large > .w3-row > .w3-col > .w3-large'); | |
let hex01 = document.getElementById('hex01'); | |
let brg = document.createElement('div'); | |
brg.classList.add('w3-margin-top'); | |
container.appendChild(brg); | |
let update_brg = function(){ | |
let text = hex01.innerText.slice(1).match(/.{2}/g); | |
let r = parseInt(text[0], 16).toString(10); | |
let g = parseInt(text[1], 16).toString(10); | |
let b = parseInt(text[2], 16).toString(10); | |
brg.textContent = [b,r,g].join(','); | |
}; | |
new MutationObserver(function(records){ | |
update_brg(); | |
}).observe( | |
hex01, | |
{ | |
childList: true, | |
characterData: true | |
} | |
); | |
brg.addEventListener('click', function(){ | |
let range = document.createRange(); | |
range.selectNodeContents(brg); | |
let selection = window.getSelection(); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
}); | |
update_brg(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment