There are 1 previous version of this script.
// ==UserScript==
// @name Google Reader Mute & Gag Feeds
// @namespace http://www.manu-j.com/blog/
// @description Mute and Gag feeds
// @include http://www.google.com/reader/*
// @include http://reader.google.com/*
// ==/UserScript==
//
// Version 0.9
var muted_feeds = []
var gagged_feeds = []
var last_key_press = ''
var entries;
GM_registerMenuCommand('Reset Feed Preferences', reset_feeds)
function reset_feeds() {
GM_setValue('muted_feeds',"[]")
GM_setValue('gagged_feeds',"[]")
document.location.reload();
}
function init() {
entries = document.getElementsByClassName("entry")
if(entries.length == 0) {
window.setTimeout(init,100);
} else {
start_m_g()
var chrome_viewer_container = document.getElementById('chrome-viewer-container')
chrome_viewer_container.addEventListener("DOMNodeInserted",re_modify, false)
}
}
function re_modify() {
if(typeof timeoutID == "number") {
window.clearTimeout(timeoutID);
timeoutID = null;
}
timeoutID = window.setTimeout(init, 700);
}
function start_m_g() {
if(is_valid_env()) {
muted_feeds = GM_getValue('muted_feeds')
gagged_feeds = GM_getValue('gagged_feeds')
entries = document.getElementsByClassName("entry")
for(i=0;i<entries.length;i++) {
var entry = entries[i];
entry.addEventListener('click',expand_current_entry,true)
if(muted_feeds.indexOf(get_feed_url(entry)) != -1 && document.getElementById('chrome-title').innerHTML == "All items") {
entry.getElementsByClassName("entry-body")[0].style.display = 'none'
entry.getElementsByClassName("entry-author")[0].style.display = 'none'
entry.getElementsByClassName("card-actions card-bottom")[0].style.display = 'none'
}
if(gagged_feeds.indexOf(get_feed_url(entry)) != -1 && document.getElementById('chrome-title').innerHTML == "All items") {
entry.style.display = 'none'
}
}
}
}
function expand_current_entry() {
entry = get_current_entry()
if(entry) {
entry.getElementsByClassName("entry-body")[0].style.display = 'block'
entry.getElementsByClassName("entry-author")[0].style.display = 'block'
entry.getElementsByClassName("card-actions card-bottom")[0].style.display = 'block'
}
}
function get_current_entry() {
var entry = document.getElementById('current-entry')
if(entry != null && entry != '') {
return entry
} else {
return false
}
}
function get_current_title() {
var current_entry = get_current_entry()
return current_entry.getElementsByClassName("entry-source-title")[0].innerHTML
}
function get_feed_url(entry) {
var feed_url = ''
var href = entry.getElementsByClassName('entry-title-link')[0].href
pieces = href.split('/')
if(pieces[2] == "feedproxy.google.com") {
feed_url = pieces[0] + '//' + pieces[2] + '/' + pieces[3] + '/' + pieces[4]
if(pieces[4] == "blogspot")
feed_url += '/' + pieces[5]
} else {
feed_url = pieces[0] + '//' + pieces[2]
}
return feed_url
}
function get_current_feed_url() {
return get_feed_url(document.getElementById('current-entry'))
}
function show_no_entry_error() {
alert("You have to select an entry to enable Muting and Gagging")
}
function set_value(label, value) {
return GM_setValue(label, uneval(value))
}
function get_value(label) {
return eval(GM_getValue(label,"[]"))
}
function is_valid_env() {
return document.getElementById('view-cards').getAttribute('class') == "unselectable link link-selected"
}
function show_not_validenv_error() {
alert("You need to be in the Exapnded Vie for Muting and Gagging")
}
function gag() {
var message
var ans
if(is_valid_env()) {
if(get_current_entry()) {
gagged_feeds = get_value('gagged_feeds')
var url = get_current_feed_url()
var index = gagged_feeds.indexOf(url)
if( index == -1) {
message = "Are you sure you want to Gag this feed \n" + get_current_title() +"\n\n Gagging the feed will remove its entries from the all views feed\nIf you are not sure click Cancel"
ans = window.confirm(message)
if(ans) {
gagged_feeds.push(url)
set_value('gagged_feeds', gagged_feeds)
start_m_g()
}
} else {
message = "Are you sure you want to Un-Gag this feed \n" + get_current_title() +"\n\n If you are not sure click Cancel"
ans = window.confirm(message)
if(ans) {
gagged_feeds.splice(index,1)
set_value('gagged_feeds', gagged_feeds)
expand_current_entry()
}
}
} else {
show_no_entry_error()
}
} else {
show_not_validenv_error()
}
}
function mute() {
var message
var ans
if(is_valid_env()) {
if(get_current_entry()) {
muted_feeds = get_value('muted_feeds')
var url = get_current_feed_url()
var index = muted_feeds.indexOf(url)
if( index == -1) {
message = "Are you sure you want to Mute this feed \n" + get_current_title() +"\n\n Muting the feed will show only its title in the all views feed\nIf you are not sure click Cancel"
ans = window.confirm(message)
if(ans) {
muted_feeds.push(url)
set_value('muted_feeds', muted_feeds)
start_m_g()
}
} else {
message = "Are you sure you want to Un-Mute this feed \n" + get_current_title() +"\n\n If you are not sure click Cancel"
ans = window.confirm(message)
if(ans) {
muted_feeds.splice(index,1)
set_value('muted_feeds', muted_feeds)
expand_current_entry()
}
}
} else {
show_no_entry_error()
}
} else {
show_not_validenv_error()
}
}
// Press cg to gag and cm to mute
window.addEventListener("keydown",function(e) {
kc = e.keyCode;
if(last_key_press != '') {
if(kc == 71 || kc == 103) { // g
last_key_press = ''
gag()
} else if(kc == 77 || kc == 109) { //m
last_key_press = ''
mute()
} else if(kc == 87 || kc == 119) { //w
last_key_press = 'w'
} else {
last_key_press = ''
}
} else {
if(kc == 87 || kc == 119) //c
last_key_press = 'w'
}
}, false);
init()
