// ==UserScript== // @namespace http://shog9.com/greasemonkey/scripts/ // @name CPShowAbusePosts // @author Joshua Heyer // @description Allow viewing the contents of posts deleted because of Spam / Abuse votes // @version 1.0 // @include http://*.codeproject.com/* // @include http://*.codetools.com/* // @include http://*.thecodeproject.com/* // ==/UserScript== var slamUsers = function() { var userArray = GM_getValue("slamUsers", "").split(","); var users = {}; userArray.forEach(function(el) { if ( !el ) return; var userAndTime = el.split(":"); users[userAndTime[0]] = { name: userAndTime[2], lastSlammed: new Date(userAndTime[1]) }; }); return users; }(); function SaveSlamList() { var userArray = []; for (u in slamUsers) { if ( slamUsers[u] ) userArray.push(u + ":" + slamUsers[u].lastSlammed.toString() + ":" + slamUsers[u].name); } GM_setValue("slamUsers", userArray.join(",")); } function AddSlamUser(userId, userName) { userName = userName.replace(/[:,]/g, ""); slamUsers[userId] = {name: userName, lastSlammed: ""}; SaveSlamList(); } function RemoveSlamUser(userId) { slamUsers[userId] = null; SaveSlamList(); } console.log(slamUsers); // no sense loading anything if this isn't even a forum - do a quick test for a forum table var forumTable = document.getElementById('ForumTable'); if ( forumTable ) { forumTable.addEventListener("click", function(event) { var target = event.target; while (target && !target.href) target = target.parentNode; if ( target && target.href.match(/\/script\/comments\/forums.asp/) && target.href.match(/forumid=(\d*)\S*select=(\d*)|select=(\d*)\S*forumid=(\d*)/) && target.textContent == 'Message Removed') { var forumId = RegExp.$1; var msgId = RegExp.$2; if ( !forumId ) forumId = RegExp.$4; if ( !msgId ) msgId = RegExp.$3; showContentLink(forumId, msgId); } else if ( target && target.href.match(/\/lounge.asp/) && target.href.match(/select=(\d*)/) && target.textContent == 'Message Removed') { var forumId = 1159; var msgId = RegExp.$1; showContentLink(forumId, msgId); } }, true); } // // uses the Reply page to obtain post content // function showContentLink(forumId, postId) { if ( document.getElementById(postId+"showContent") ) return; var postBody = XPathNode(document, "//tr[@id='"+postId+"_h1']/td/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr/td"); if ( postBody ) { var link = document.createElement("A"); link.id = postId+"showContent"; link.href = "#"; link.innerHTML = "Show Content"; link.addEventListener('click', function(event) { event.preventDefault(); link.innerHTML = ""; showContent(forumId, postId, postBody); }, true); postBody.appendChild(link); } } function showContent(forumId, postId, postBody) { GM_xmlhttpRequest({ method: 'GET', url: "http://" + document.location.host + "/script/comments/user_reply.asp?forumid=" + forumId + "&select=" + postId, onload: function(responseDetails) { var contentHTML = ""; if ( responseDetails.status == 200 ) { var err = checkError(responseDetails.responseText); if ( err ) contentHTML = err; else { var tmpDiv = document.createElement("DIV"); tmpDiv.style.display = "none"; tmpDiv.innerHTML = responseDetails.responseText; var content = XPathNode(tmpDiv, ".//td[@class='ContentPane']/table[3]/tbody/tr[2]/td/table/tbody/tr/td"); if ( content ) contentHTML = "
" + content.innerHTML + "
"; } } else { contentHTML = 'Failed to obtain message: ' + responseDetails.status + ' ' + responseDetails.statusText; } postBody.innerHTML = contentHTML; var postHeader = XPathNode(document, "//tr[@id='"+postId+"_h0']"); if ( !postHeader) return; var userId = (XPathString(postHeader, "./td[last()-2]/a/@href").match(/id=(\d*)/) ? RegExp.$1 : null); if ( !userId ) return; var userName = XPathNode(postHeader, "./td[last()-1]").textContent.replace(/\s+$/, ''); var link = document.createElement("A"); link.id = postId+"slamUser"; link.href = "#"; link.innerHTML = "Vote-slam " + userName + ""; link.addEventListener('click', function(event) { event.preventDefault(); AddSlamUser(userId, userName); }, true); postBody.appendChild(link); } }); } // // Look for an error message in the response text, extract it if found // function checkError(responseText) { if ( responseText.indexOf("An Error occured!") >= 0) // look for error message { var error; if ( responseText.match(/

Error description:<\/p>\s*(

[\s\S]*(?:<\/blockquote))/gi) ) error = RegExp.$1; if ( error ) { var tmp = document.createElement("DIV"); tmp.style.display = "none"; tmp.innerHTML = error; error = tmp.textContent; return error; } } return false; } function XPathNode(el, xpath) { // Firefox trunk builds don't like the fact that, when we pass in the Midas body, we're using the node outside the context in which it was created. This should help. var scope = (el.ownerDocument == null ? document : el.ownerDocument); try { var result = scope.evaluate(xpath, el, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); return (result && result.singleNodeValue ? result.singleNodeValue : null); } catch (e) { console.error("Error processing xpath: \n%s\n%.o", xpath, e); } return null; } function XPathString(el, xpath) { try { return document.evaluate(xpath, el, null, XPathResult.STRING_TYPE, null).stringValue; } catch (e) { console.error("Error processing xpath: \n%s\n%.o", xpath, e); } return null; } // slam users var userList = document.createElement("DIV"); for (u in slamUsers) { var userId = u; var userName = slamUsers[u].name; var link = document.createElement("A"); link.href = "#"; link.innerHTML = "Stop vote-slamming " + userName + ""; link.addEventListener('click', function(event) { event.preventDefault(); RemoveSlamUser(userId); }, true); userList.appendChild(link); userList.appendChild(document.createElement("BR")); } document.body.appendChild(userList);