Skip to content

Commit

Permalink
initial plurk delete greasemonkey script import
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrumins committed Nov 30, 2009
0 parents commit 880b8e8
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
106 changes: 106 additions & 0 deletions deleteplurks.user.js
@@ -0,0 +1,106 @@
//
// Delete Plurks v1.0 2009.11.29
//
// A greasemonkey script by Peteris Krumins (peter@catonmat.net)
// http://www.catonmat.net -- good coders code, great reuse
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey:
// https://addons.mozilla.org/en-US/firefox/addon/748
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Delete Plurks
// @namespace http://www.catonmat.net
// @description Adds a button to delete plurks on individual plurk page.
// @include http://www.plurk.com/p/*
// ==/UserScript==

(function() {

function xpath(query) {
var elems = document.evaluate(query, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var ret = [];
for (var i = 0; i < elems.snapshotLength; i++) {
ret.push(elems.snapshotItem(i));
}
return ret;
}

function xpath_map(query, fn) {
var elements = xpath(query);
for (var i = 0; i < elements.length; i++) {
fn(elements[i]);
}
}

function delete_plurk(plurk_id, id, li)
{
var url = 'http://www.plurk.com/Responses/deleteResponse';
var data = 'plurk_id=' + plurk_id + '&id=' + id;
GM_xmlhttpRequest({
method: 'POST',
url: url,
data: data,
headers: {
Referer: 'http://www.plurk.com',
'Content-type': 'application/x-www-form-urlencoded'
},
onload: function(response) {
li.style.display = "none";
}
});
}

function element_str(query, filter) {
try {
str = xpath(query)[0].textContent;
if (str) {
return filter(str);
}
}catch(e){}
}

function get_my_nick() {
return element_str('//a[@id="login_link"]',
function(str){
return str.match(/Sign out \[(.+)\]/)[1].toLowerCase();
});
}

function get_owner_nick() {
return element_str("//a[@class='user-nick']",
function(str){
return str.toLowerCase();
});
}

var my_nick = get_my_nick();
var owner_nick = get_owner_nick();

var plurk_id_36 = document.location.href.match(/\/p\/(.+)/)[1];
var plurk_id = parseInt(plurk_id_36, 36);

xpath_map("//li[contains(@id, 'response')]",
function(li) {
var id = li.id.match(/\d+/);
var div = li.childNodes[3];
var nick = div.childNodes[3].textContent.toLowerCase();

if (owner_nick == my_nick || nick == my_nick) {
var a = document.createElement('a');
a.href='#delete';
a.innerHTML = "delete";
a.addEventListener('click', function(evt) {
delete_plurk(plurk_id, id, li);
}, false);
div.appendChild(a);
}
});
})();

50 changes: 50 additions & 0 deletions readme.txt
@@ -0,0 +1,50 @@
This is a GreaseMonkey script that adds a "delete" button on individual plurk
page. This way you can delete your or other people plurks (if it's your
thread) from the plurk page itself.

This script was written by Peteris Krumins (peter@catonmat.net).
His blog is at http://www.catonmat.net -- good coders code, great reuse.

His profile at Plurk is at http://plurk.com/pkrumins - come be his friend! :)

The code is licensed under the MIT license.

------------------------------------------------------------------------------

How to install this script?
---------------------------

You will need FireFox browser and GreaseMonkey plugin. If you have them,
please proceed to step 3. Otherwise also do steps 1 and 2.

Step 1. Download and install FireFox browser. It can be downloaded at the
following address: http://www.mozilla.com/firefox/

Step 2. Install GreaseMonkey FireFox addon. GreaseMonkey allows you to modify
any page (like this one adds translation feature to Plurk's page). GreaseMonkey
can be downloaded here: https://addons.mozilla.org/en-US/firefox/addon/748

Step 3. Install this script. The latest version is always at GreaseMonkey
script repostiory:

http://userscripts.org/scripts/source/63085.user.js

Open this link with FireFox and click "Install".

Now you can delete plurks from the individual plurk page. (By individual plurk
page I mean plurks with URL http://www.plurk.com/p/<something>).

The script will add "delete" button next to your own plurks.

The script will add "delete" button to all the plurks if you are the owner of
the thread (the original plurk).

------------------------------------------------------------------------------

And yeah, follow me on Plurk: http://plurk.com/pkrumins


Sincerely,
Peteris Krumins
http://www.catonmat.net

0 comments on commit 880b8e8

Please sign in to comment.