// Elecraft Nabble Forum Move Script // version 0.55 BETA! // 2010-08-12 // Copyright (c) 2009-2010, Leigh L. Klotz, Jr. // Metadata format from Mark Pilgrim (c) 2005 // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // // -------------------------------------------------------------------- // // 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 "Nabble Move Elecraft Topics", and click Uninstall. // // Bugs: When on the main forum page, it falsely matches on the child forum // name itself. // TODO: Mark a list of subjects instead of just one. // To change this script for other Nabble2 subforums, edit // unsafeWindow.mainForumUrl to point to your main forum page, // and edit unsafeWindow.forumUrls to point to the child forums. // -------------------------------------------------------------------- // // ==UserScript== // @name Nabble Move Starred Elecraft Topics // @namespace http://wa5znu.org/2009/08/nabble-move-starred-topics // @description Move all starred topics on the current page to another forum // @include http://elecraft.365791.n2.nabble.com/* // ==/UserScript== unsafeWindow.mainForumUrl = 'http://elecraft.365791.n2.nabble.com'; unsafeWindow.starUrl = 'http://elecraft.365791.n2.nabble.com/template/TplServlet.jtp?tpl=set_star&'; unsafeWindow.forumUrls = { 'K3': '/K3-f365792.html', 'K2': '/K2-f365793.html', 'K1': '/K1-f365794.html', 'KX1':'/KX1-f365795.html', 'MM': '/MM-f786095.html', 'HAM':'/HAM-f786097.html', 'QRO':'/QRO-f4919483.html', 'OT': '/OT-f786099.html' }; unsafeWindow.forumSubjects = { 'K3': ['K3', 'P3', 'KAT3'], 'K2': ['K2', 'KPA2', 'KAT2', 'KRC2', 'KIO2' ], 'K1': ['K1', 'K1'], 'KX1':['KX1', 'KX-1'], 'QRO':['KPA500'] } unsafeWindow.markSubjects = function(key) { var allSubjects, thisSubject; var keys = unsafeWindow.forumSubjects[key] for (var keyidx in keys) { var str = keys[keyidx]; var xp = "//a[@embed='fixTarget' and contains(text(),'"+str+"')]"; allSubjects = document.evaluate(xp, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); len = allSubjects.snapshotLength; // todo if we are on main page subforum itself matches if (len > 0) { alert(str + " " + len); } for (var i = 0; i < len; i++) { thisSubject = allSubjects.snapshotItem(i); var x = document.evaluate("../../../../../following-sibling::td/span/img/@id", thisSubject, null, XPathResult.STRING_TYPE, null); imgid = x.stringValue; if (imgid != "" && imgid != null) { postnum = imgid.substring(9); // TODO: 9 may not be constant if (i == len - 1 || len == 1) get(unsafeWindow.starUrl, 'node='+postnum+'&star=true', reloadPage); else get(unsafeWindow.starUrl, 'node='+postnum+'&star=true', donothing); } } } } unsafeWindow.unstarAll = function() { var allStars, thisStar, imgid, postnum, len, starred; allStars = document.evaluate('//img[@title="Starred (click to unstar it)"]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); starred = ""; len = allStars.snapshotLength; for (var i = 0; i < len; i++) { thisStar = allStars.snapshotItem(i); imgid = thisStar.getAttribute("id"); if (imgid != "" && imgid != null) { postnum = imgid.substring(9); // TODO: 9 may not be constant if (i == len - 1 || len == 1) get(unsafeWindow.starUrl, 'node='+postnum+'&star=false', reloadPage); else get(unsafeWindow.starUrl, 'node='+postnum+'&star=false', donothing); } } } unsafeWindow.moveToForum = function(newForum) { var allStars, thisStar, imgid, postnum, len, starred, forumUrl; if (! newForum in unsafeWindow.forumUrls) { alert('bad forum ' + newForum); return false; } forumUrl = escape(unsafeWindow.mainForumUrl + unsafeWindow.forumUrls[newForum]); allStars = document.evaluate('//img[@title="Starred (click to unstar it)"]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); starred = ""; len = allStars.snapshotLength; for (var i = 0; i < len; i++) { thisStar = allStars.snapshotItem(i); imgid = thisStar.getAttribute("id"); if (imgid != "" && imgid != null) { postnum = imgid.substring(9); // TODO: 9 may not be constant var entity = 'form=y&tpl=move_node&node='+postnum+'&parent_url='+forumUrl; var pathinfo = '/template/TplServlet.jtp?tpl=move_node&node='+postnum; if (i == len - 1 || len == 1) post(unsafeWindow.mainForumUrl + pathinfo, entity, finishAndUnstar); else post(unsafeWindow.mainForumUrl + pathinfo, entity, donothing); } } }; function finishAndUnstar() { unsafeWindow.unstarAll(); } function inform(text) {alert(text);} function donothing(text) {} function reloadPage(text) {unsafeWindow.location.reload()} function firstNodeOf(html){ firstNodeOf.dummyDiv.innerHTML = html; return firstNodeOf.dummyDiv.firstChild; } firstNodeOf.dummyDiv = document.createElement('div'); // you must call encodeURI yourself on data parts function post(url, data, cb) { setTimeout(function () { GM_xmlhttpRequest({ method: "POST", url: url, headers:{'Content-type':'application/x-www-form-urlencoded'}, data: data, onerror: function(xhr) { alert("error " +xhr.statusText); }, onload: function(xhr) { cb(xhr.responseText); } }); }, 0); } // you must call encodeURI yourself on data parts function get(url, data, cb) { setTimeout(function () { GM_xmlhttpRequest({ method: "get", url: url+(data), onload: function(xhr) { cb(xhr.responseText); } }); }, 0); } { var markers = '