User:Aesulus/common.js: Difference between revisions

m
compatibility with older browsers
(fix regex; make code slightly more readable)
m (compatibility with older browsers)
Line 1:
function getPekoCookie(key) {
constvar matchArray = document.cookie.match(new RegExp('\\b' + key + '=([^;]+)'));
return (matchArray == null) ? null : matchArray[1];
Line 11:
function addButton() {
// create the button
constvar pekofyButton = document.createElement('a');
pekofyButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.8 -0.5 235 235"><circle id="pekofyButtonCircle" cx="116.7" cy="117" r="117.5" fill="#59a4f0" /><g transform="matrix(.657932 1.139572 -1.139572 .657932 169.93483 23.952904)"><path id="pekofyButtonCarrot" d="M34.131 50.271l-.888.022-.876.067-.862.108-.848.151-.834.19-.818.232-.8.27-.781.307-.763.343-.741.378-.72.414-.698.447-.674.478-.65.509-.623.54-.597.568-.568.597-.54.623-.509.65-.479.674-.445.698-.414.72-.378.742-.344.761-.306.782-.27.8-.232.816-.191.834-.15.849-.11.862-.065.876-.022.888.105 6.532h14.472a2.09 2.09 0 0 1 2.09 2.09 2.09 2.09 0 0 1-2.09 2.09H17.222c.312 6.415.902 12.676 1.754 18.619h12.535a2.09 2.09 0 0 1 2.09 2.09 2.09 2.09 0 0 1-2.09 2.09H19.643c1.147 6.864 2.642 13.135 4.431 18.582l.013.037h7.424a2.09 2.09 0 0 1 2.09 2.09 2.09 2.09 0 0 1-2.09 2.09h-5.896c4.321 10.972 9.768 16.989 15.395 17.006 3.175-.007 6.318-1.926 9.249-5.646a2.09 2.09 0 0 1-1.839-2.05 2.09 2.09 0 0 1 2.09-2.09h2.464c1.814-3.14 3.487-6.984 4.975-11.436.735-2.256 1.42-4.655 2.053-7.182H50.51a2.09 2.09 0 0 1-2.09-2.09 2.09 2.09 0 0 1 2.09-2.09h10.503c1.264-5.753 2.254-12.021 2.94-18.619H50.51a2.09 2.09 0 0 1-2.09-2.09 2.09 2.09 0 0 1 2.09-2.09h13.814a217.58 217.58 0 0 0 .763-17.932 17.61 17.61 0 0 0-.018-.687H50.51a2.09 2.09 0 0 1-2.09-2.09 2.09 2.09 0 0 1 2.09-2.09h13.88l-.073-.258c-.084-.27-.174-.536-.27-.8s-.197-.525-.306-.782-.224-.511-.344-.761a17.11 17.11 0 0 0-.378-.742c-.132-.244-.271-.484-.414-.72a17.06 17.06 0 0 0-.445-.698c-.154-.229-.315-.453-.479-.674s-.334-.438-.509-.65a17.2 17.2 0 0 0-.54-.623 17.21 17.21 0 0 0-.568-.597c-.194-.194-.393-.384-.597-.568s-.411-.365-.623-.54-.43-.344-.65-.509a17.15 17.15 0 0 0-.674-.478c-.229-.154-.461-.303-.698-.447s-.475-.282-.718-.414-.491-.258-.742-.378a17.11 17.11 0 0 0-.763-.343c-.257-.108-.517-.211-.781-.307s-.53-.187-.8-.27-.543-.161-.818-.232a17.14 17.14 0 0 0-.834-.19c-.28-.057-.562-.108-.848-.151a17.34 17.34 0 0 0-.862-.108c-.29-.029-.582-.052-.876-.067s-.59-.022-.888-.022z" fill="#ffa94c"/><path id="pekofyButtonStem" d="M41.011 0c-4.066 0-7.456 1.936-9.26 5.292s-3.588 11.979-1.323 15.875c2.313 3.978 6.946 6.517 7.938 10.583.733 3.106 0 13.229 0 13.229-.962-.847-.972-2.11-1.323-2.646-2.756-8.446-8.695-14.35-17.198-14.552C10.585 27.837.243 34.497 0 43.656c0 6.63 6.615 9.26 11.906 9.26 6.615 0 14.552-10.583 17.198-10.583s3.487 2.985 3.969 6.615h5.292 2.646 2.646 5.292c.481-3.629 1.323-6.615 3.969-6.615S63.5 52.917 70.115 52.917c5.292 0 11.906-2.631 11.906-9.26-.242-9.159-10.584-15.82-19.844-15.875-8.503.202-14.442 6.106-17.198 14.552-.351.535-.361 1.799-1.323 2.646 0 0-.733-10.124 0-13.229.992-4.067 5.625-6.605 7.938-10.583 2.265-3.896.481-12.519-1.323-15.875S45.076 0 41.011 0z" fill="#79e02b"/></g></svg>';
pekofyButton.setAttribute('style', 'width: 72px; z-index: 100; position: fixed; bottom: 0px; right: 0px; margin: 10px;');
Line 19:
// the stylesheet
constvar style = document.createElement('style');
style.textContent = '\
body.isPeko .mw-wiki-logo {\
Line 46:
// initialize based on value of cookie
constvar pekofyButtonState = getPekoCookie('pekofyButtonState');
if (pekofyButtonState == "true") {
Line 72:
}
if (node.tagName == "IMG") { // logo replacement
constvar logoPattern = new RegExp('https://static.miraheze.org/hololivewiki/thumb/f/f3/HololiveFanWiki-logo-black.png(/\d+px-HololiveFanWiki-logo-black.png)?');
if (logoPattern.test(node.getAttribute('src'))) {
node.unpekofied = node.getAttribute('src');