byr-signature

add signature for byr-forum

目前為 2016-06-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         byr-signature
// @namespace    flowmemo
// @version      0.1
// @description  add signature for byr-forum
// @author       flowmemo
// @match        https://bbs.byr.cn/*
// @grant        GM_getValue
// @grant        GM_setValue
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var defaultSig = '\n' +
        '————\n' +
        '示例签名:' +
        '微博 [url=http://weibo.com/flowmemo]@flowmemo[/url] 现在主要写JavaScript. 关注广泛, 欢迎交流.';
    var id; // timeout id
    var div;
    function addSignature (sig) {
        var signature = GM_getValue('sig', defaultSig);
        console.log('/post');
        div = document.getElementById('post_content');
        if(!div) return;
        console.dir(div);
        console.log('change value');
        div.value += signature;
        return true;
    }
    function polling() {
        window.clearTimeout(id); // clear timeout if it exist
        if (window.location.href.indexOf('/post') === -1) return;
        function cb () {
            if (addSignature()) {
                sigPanel();
                return;
            }
            id = setTimeout(cb, 300);
        }
        cb();
    }
    function sigPanel() {
        var div = document.createElement('div');
        var referNode = document.getElementsByClassName('post-list-item')[2];
        referNode.appendChild(div);

        console.log(div.outerHTML);
        div.outerHTML = '<br><div class="byr-signature">' +
            '<div class="post-m">byr-signature</div>' +
            '<textarea class="post-textarea"name="sig-content" placeholder="在此输入你的签名, 保存后刷新页面生效"></textarea><br>' +
            '<input name="saveSig" type="button" value="保存"></div>';
        var userSig = document.getElementsByName('sig-content')[0];
        userSig.value = GM_getValue('sig', defaultSig);
        var saveButton = document.getElementsByName('saveSig')[0];
        saveButton.onclick = function() {
            console.log(userSig.value);
            GM_setValue('sig', (userSig.value));
        };
    }
    if (window.location.href.indexOf('/post') > -1) polling();
    console.log('add change');
    window.addEventListener('hashchange', polling);
})();