Saturday, April 4, 2009

Salon Letter Filter Script

[WARNING: This script can no longer be used due to changes in Salon's Letter format. The new script is here.]
[On 11/10/09 Salon again changed the format of their letter pages. A new script to filter Salon letters is again available here. The old code is left here in case Salon changes the format back again.]
For those who have been unable to install the Salon Letter Filter Greasemonkey script from the link to the file, here is the text of the script. To install, copy everything between //BEGIN CODE and //END CODE into a text file (do not copy //BEGIN CODE and //END CODE). Name the text file salonletterfilter.user.js and save it. Open the file in your browser (you can drag and drop). If Greasemonkey is installed and active, when you open the file a Greasemonkey dialog will appear asking if you want to install the script. Click on install.

IMPORTANT: Your file name must end with .user.js for Greasemonkey to recognize it as a user script.

Do not panic if it appears that the lines of code end in midair on the blog page. It is all there even if it doesn't display because of the Blogger page layout. Simply select the code, copy it, and paste it into a new text file. Notepad or some other fairly simple text editor is recommended for this.
//BEGIN CODE
//
// MANUAL CONFIGURATION REQUIRED
//
// To configure the letters filter, you must have a "killfile" variable configured.
// A template for this variable is given below. The "killfile" varable includes a
// comma-delimited string of the nyms of the authors that you wish to filter out.
// A sample "killfile variable configuration looks like:
//
// new String(killfile = 'author1,author2,author3');
// or
// new String(killfile = 'author');
//
// Simply replace the word "authors" in the template below with the nyms of the authors you
// wish to expunge, each one separated by a comma, and save the file.
// Entries are case insensitive. Since the "killfile" will become a regular expression,
// regular expression metacharacters (such as "." or "+") appearing in a nym should be
// preceded by a backslash ("\"; e.g., 'L\.W\.M\.') in order to work properly.
//
new String(killfile = 'authors');
if (killfile.length == 0) exit;
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "Letter_Filter", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Salon Letter filter
// @author Frankly, my dear, ...
// @namespace http://language-grammar.blogspot.com/2009/04/filter-for-salon-letters.html
// @description Filter letters from Salon. WARNING: manual configuration required. Before use you must edit the script and enter your "killfile" in the string variable near the top of the script.
// @include http://letters.salon.com/*
// @version 0.0.1
// ==/UserScript==

//
// Set debug to 1 to see debug output in Javascript console
//
var debug = 1;


//
// Only print information to console if debug is on
//
function myGM_log(args) {
if (debug == 1) {
GM_log(args);
}
}


//
// Shortcut function to evalute an XPath in the document
//
function xpath(query, sourceDoc) {
return document.evaluate(query, sourceDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}

myregexp = new RegExp(killfile.replace(/, */g, "|"), "i");
myGM_log(myregexp);
var allLets, thisLet, allAuthors, thisAuthor, allFooters, thisFooter;
allLets = xpath("//li[@class='letter_node']",document);
allAuthors = xpath("//div[@class='letter_entry_author'] | //div[@class='letter_entry_author premium']",document);
allFooters = xpath("//div[@class='letter_entry_footer']",document);
for (var i = 0; i < allLets.snapshotLength; i++) {
thisLet = allLets.snapshotItem(i);
thisAuthor = allAuthors.snapshotItem(i);
thisFooter = allFooters.snapshotItem(i);
var author = thisAuthor.innerHTML;
if (myregexp.test(author)) {
mymatch = myregexp.exec(author);
thisLet.innerHTML = "<h3><b>Letter from " + mymatch + " deleted</h3></b>" + thisFooter.innerHTML +"<hr>";
//thisLet.innerHTML = "";
}
}
//END CODE

5 comments:

mikeinportc said...

...but this is the kind of simple programming task....

If you say so . :) I'll just scroll past the annoying ones . Thanks anyway.

mike said...

It appears they might have broken it again--although I've made no recent changes, the script now only seems to catch about 50% of the blocked-author's letters.

QualityPoint said...

It is very nice post.It is good post. It is simple and best. It helpful for future use.You can test your knowledge in html by attending HTML Quiz .

lee said...

Benjamin Pineda Gomez stated he previously zero name or even information about the person who diedSYour Mexican fast claimed overdue Mon it Discount Burberry Cheap is going to increase the actual seek place pertaining to children right after meeting with different saving firms, in spite of previously nike air jordan clearance stories these were thinking about transforming their own attempts in order to recovering body almost 48 hrs after the early on On authentic nike air jordan the morning car accident Which beach can be quiet," he was quoted saying It won't point out an excuse or perhaps give Air Jordan Cheap you a particular date An area magazine, your Billings Gazette, has operate pictures of an turtle along with a group of pelicans Cheap Air Max apparently along with gas with them "We have to incorporate harder safety expectations Sam Michaud, Forty two, exactly who qualified WilliamYour royal Discount Burberry set of two quit Canada's tiniest domain later Wednesday mid-day William set the mitts his or her belly along with joked with Ed Hardy regards to overindulging within the trip

Vicky Liang said...

Thank you for sharing your story with us!Sony Laptop Batteries