Skip to content

Instantly share code, notes, and snippets.

@Namek
Created November 4, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Namek/c3e1ce8b82b8642f0d0a to your computer and use it in GitHub Desktop.
Save Namek/c3e1ce8b82b8642f0d0a to your computer and use it in GitHub Desktop.
Tampermonkey script: Different Trello background every day Raw
// ==UserScript==
// @name Trello
// @namespace http://namekdev.net
// @version 0.2
// @description different Trello background every day
// @author Namek
// @include /^https?://trello\.com/?.*$/
// @grant none
// ==/UserScript==
function createStyle(css) {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
return style;
}
// got it from here: https://gist.github.com/BrockA/2625891
function waitForKeyElements (
selectorTxt, /* Required: The jQuery selector string that
specifies the desired element(s).
*/
actionFunction, /* Required: The code to run when elements are
found. It is passed a jNode to the matched
element.
*/
bWaitOnce, /* Optional: If false, will continue to scan for
new elements even after the first match is
found.
*/
iframeSelector /* Optional: If set, identifies the iframe to
search.
*/
) {
var targetNodes, btargetsFound;
if (typeof iframeSelector == "undefined")
targetNodes = $(selectorTxt);
else
targetNodes = $(iframeSelector).contents ()
.find (selectorTxt);
if (targetNodes && targetNodes.length > 0) {
btargetsFound = true;
/*--- Found target node(s). Go through each and act if they
are new.
*/
targetNodes.each ( function () {
var jThis = $(this);
var alreadyFound = jThis.data ('alreadyFound') || false;
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction (jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data ('alreadyFound', true);
}
} );
}
else {
btargetsFound = false;
}
//--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {};
var controlKey = selectorTxt.replace (/[^\w]/g, "_");
var timeControl = controlObj [controlKey];
//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval (timeControl);
delete controlObj [controlKey]
}
else {
//--- Set a timer, if needed.
if ( ! timeControl) {
timeControl = setInterval ( function () {
waitForKeyElements ( selectorTxt,
actionFunction,
bWaitOnce,
iframeSelector
);
},
300
);
controlObj [controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}
var colors = ["673ab7","3f51b5","2196f3","03a9f4","0288d1","01579b","006064","26c6da","0091ea","4caf50","2e7d32","00695c","64ffda","00c853","8bc34a","ffc107","ffb300","ff9800","f4511e","bf360c","795548","9e9e9e","fafafa","9e9e9e","757575","6d4c41","607d8b","b0bec5","78909c","455a64","212121"];
var oneDayInMs = 1000*60*60*24;
var currentTimeInMs = new Date().getTime(); // UTC time
var timeInDays = Math.floor(currentTimeInMs / oneDayInMs);
var numberForToday = timeInDays % 9999;
var index = numberForToday % colors.length;
var color = '#' + colors[index];
var style = createStyle('body{background-color:' + color + ' !important;}');
var alreadyAdded = false;
// add style on board page
waitForKeyElements(".board-wrapper", function() {
if (!alreadyAdded) {
document.body.appendChild(style);
alreadyAdded = true;
}
});
// remove style on board list page
waitForKeyElements('.member-boards-view', function() {
if (style.parentNode) {
style.parentNode.removeChild(style);
}
alreadyAdded = false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment