GreaseMonkey

From James Van Dyne
Jump to navigation Jump to search

My collection of grease monkey scripts I use to make the web work better for me.

Header Color

Changes the background of an element red. Useful for when you want an easy visual distinction that your on your own repository.

// ==UserScript==
// @name     header color
// @version  1
// @grant    none
// @include https://github.com/jamesvandyne/*
// @run-at document-idle
// ==/UserScript==

function addStyleBlock(cssString) {
  let head = document.getElementsByTagName("head")[0];
  let newCss = document.createElement("style");
  newCss.type = "text/css";
  newCss.innerHTML = cssString;
  head.appendChild(newCss);
}

function appendClass(element, className) {
  element.classList.add(className);
}
addStyleBlock (".red-background { background-color: #FF000085 !important; }");

// Github Header
let header = document.getElementById("js-repo-pjax-container");
if(header) {
   appendClass(header.getElementsByTagName("div")[0], "red-background");
}