stfu

silence of the spam

目前為 2016-04-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name           stfu
// @namespace      2
// @description    silence of the spam
// @version        1.05
// @include        http://blogs.crikey.com.au/*
// @include        http://www.crikey.com.au/*
// @require 	   https://greasyfork.org/scripts/1884-gm-config/code/GM_config.js?version=4836
// ==/UserScript==
// Ver 0.04
// Add wordfilter
// Ver 1.00
// Add config dialog
// Ver 1.01
// Add GM/TM menu access to config dialog
// Ver 1.02
// Fix lower case bug
// Ver 1.03
// Better defensive code around get class
// Ver 1.04
// move GM_Config to Greasy Fork
// Ver 1.05
// Fixed issue for Firefox

// The first rule of stfu: stfu about stfu
var scriptVer = '1.05';
var scriptLoc = 'https://greasyfork.org/en/scripts/18683-stfu';

//don't run in iframes
if (window.top !== window.self) {
    return;
}

////////////////////////////////////////////////////////////////////////////////
// Config settings dialog
GM_config.storage = 'stfu';
GM_config.init('Better Bludging', 
	{
		authorFilter: {
			label: 'Author filter (use the format: \'bob1234|L. Ron Hubbard|Joseph Smith, Jr.\')',
			type: 'text',
			'default': 'bob1234',
			size:50
		},
		wordFilter: {
			label: 'Word/phrase filter (use the format: \'programmatic specificity|leadership rumblings\')',
			type: 'text',
			'default': '',
			size:50
		}
	},
	{
		save: function() { location.reload(); } // reload the page when configuration was changed
	}
);
////////////////////////////////////////////////////////////////////////////////

function showConfigSTFU() {
	GM_config.open();
}

////////////////////////////////////////////////////////////////////////////////

// Add config link on page
var stfu_showconfig = document.createElement('span');
stfu_showconfig.style.clear = 'both';
var stfu_showconfiglink = document.createElement('a');
stfu_showconfiglink.id = 'stfu-showconfig';
stfu_showconfiglink.style.color = 'blue';
stfu_showconfiglink.innerHTML = 'stfu Settings';
stfu_showconfig.appendChild(stfu_showconfiglink);
stfu_showconfig.addEventListener("click", showConfigSTFU, false);
var stfu_showconfigpad = document.createElement('span');
stfu_showconfigpad.style.clear = 'both';
stfu_showconfigpad.innerHTML = '      ';
	
var cccp_helper = document.getElementById("cccp-helper");
if (cccp_helper != null) {
	var spa = cccp_helper.getElementsByTagName('span');
	if (spa != null && spa.length >= 3) {
		cccp_helper.insertBefore(stfu_showconfig, spa[2]);
		cccp_helper.insertBefore(stfu_showconfigpad, spa[2]);
	}
} else {
	var comments=document.getElementById("comments");
	if (comments != null) {
		var stfu_option = document.createElement('div');
		stfu_option.setAttribute("id","stfu-option");
		stfu_option.appendChild(stfu_showconfig);
		var clear=document.createElement('div');
		clear.setAttribute("class","clear");
		comments.appendChild(clear.cloneNode(0)); 
		comments.appendChild(stfu_option); 
	}
}

////////////////////////////////////////////////////////
function toggleComment(){
  var elem = this.parentNode.nextSibling;
  if (elem.style.display == 'none') {
    elem.style.display = 'block'
    this.innerHTML = this.innerHTML.replace(/Show Comment/g,'Hide Comment');
  } else {
    elem.style.display = 'none'
    this.innerHTML = this.innerHTML.replace(/Hide Comment/g,'Show Comment');
  }
}
////////////////////////////////////////////////////////

var authorFilter = GM_config.get('authorFilter').toLowerCase();
var wordFilter = GM_config.get('wordFilter');

// Hide posts by blacklisted authors
if (authorFilter != null && authorFilter.length > 0 && document.getElementById('comments-list') != null) {
	var af = '^' + authorFilter.replace(/\|/g,'$|^') + '$';
	Array.filter( document.getElementById('comments-list').getElementsByClassName('fn'), function(elem){
	  var author = elem.innerHTML.toLowerCase();
	  if (author.match(af)) {
		 elem.parentNode.parentNode.style.display = 'none';
		 var newNodeP = document.createElement('p');
		 var newNodeA = document.createElement('a');
		 newNodeA.addEventListener("click", toggleComment, true);
		 newNodeP.appendChild(newNodeA);
		 elem.parentNode.parentNode.parentNode.insertBefore(newNodeP,elem.parentNode.parentNode);
		 newNodeA.innerHTML = author + ' - Show Comment (Author)';
		 newNodeA.style.color = '#99CC33';
	  } else {
		 elem.parentNode.parentNode.style.display = 'block';
	  }
	});
}

// Hide posts containing words found in the word filter
if (wordFilter != null && wordFilter.length > 0) {
	var wf = wordFilter.toLowerCase();
	Array.filter( document.getElementById('comments-list').getElementsByTagName('li'), function(elem){
	  var text = elem.innerHTML.toLowerCase();
	  if (elem.style.display == 'block' && text.match(wf)) {
		 elem.style.display = 'none';
		 var newNodeP = document.createElement('p');
		 var newNodeA = document.createElement('a');
		 newNodeA.addEventListener("click", toggleComment, true);
		 newNodeP.appendChild(newNodeA);
		 elem.parentNode.insertBefore(newNodeP,elem);
		 if (elem.getElementsByClassName('fn') != null && elem.getElementsByClassName('fn').length > 0)
			newNodeA.innerHTML = elem.getElementsByClassName('fn')[0].innerHTML + ' - Show Comment (WordFilter)';
		 else
			newNodeA.innerHTML = 'Show Comment (WordFilter)';
		 newNodeA.style.color = '#99CC33';
	  }
	});
}
////////////////////////////////////////////////////////

//GM_registerMenuCommand('stfu Settings', showConfigSTFU);