Trello - change bg set cookie

修改trello背景

Ekde 2016/12/17. Vidu La ĝisdata versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Trello - change bg set cookie
// @name:zh-CN   Trello - 修改背景
// @namespace    null
// @homepageurl  null
// @version      1.1.3
// @description  修改trello背景
// @description:zh-CN 修改trello背景图片
// @author       will
// @match        http*://*trello.com/b/*
// @grant        none
// ==/UserScript==
var setCookie = function (name, value) {
    if(localStorage){
        localStorage.setItem(name, value);
    }else{
        var days = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    }
};
var getCookie = function(name) {
    var ret = "";
    if(localStorage){
        ret = localStorage.getItem(name);
    }else{
        var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        var arr = document.cookie.match(reg);
        if (arr) {
            ret = unescape(arr[2]);
        }
    }
    return ret;
};
var addbg = function(){
    if($("body").css("background-image") == 'none'){
        var bg = getCookie('background-image') || "http://cdn.duitang.com/uploads/item/201211/29/20121129205623_QtGLE.jpeg";
        $("body").css("background-image","url("+bg+")");
    }
};

var addbgBtn = function(){
    var flag = $('#changeBg20161216').html();
    if(!flag){
        var changeBg = $('<a class="board-header-btn board-header-btn-org-name board-header-btn-without-icon"><span class="board-header-btn-text" id="changeBg20161216">修改背景</span></a>');
        $('div.board-header').append(changeBg); // 添加按钮
        changeBg.click(function(){
            var bg = getCookie('background-image') || "http://cdn.duitang.com/uploads/item/201211/29/20121129205623_QtGLE.jpeg";
            var bg_val = prompt("请输入背景地址",bg);
            if(bg_val){
                setCookie('background-image',bg_val);
                $("body").css("background-image","url("+bg_val+")");
            }
        });
    }
};
var init = function() {
    setInterval(function(){
        addbgBtn();
        addbg();
    },1000);
};

$(function(){
    init();
});