NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
/* SCP-Wiki Real Votes version 1.8 2015-11-23 -------------------------------------------------------------------- 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 "SCP-Wiki Real Votes", and click Uninstall. -------------------------------------------------------------------- */ // ==UserScript== // @name SCP-Wiki Real Votes // @description Counts the real amount of votes for an article // @include http://www.scp-wiki.net/* // @include http://scp-wiki.wikidot.com/* // @exclude http://www.scp-wiki.net/forum* // @exclude http://scp-wiki.wikidot.com/forum* // @license CC-BY-SA-3.0; https://creativecommons.org/licenses/by-sa/3.0/ // @grant GM_xmlhttpRequest // ==/UserScript== /* * Removes all whitespace from the beginning and the end of a string * * Usage: myString.trim() * Returns: string, the string the function is applied to, stripped of all whitespace at the beginning and end. */ String.prototype.trim = function () { var returnValue = this.replace(/^\s+|\s+$/g, ""); return returnValue; } var scripts = document.getElementsByTagName('script'); var pageID, pageName, pair, part, scriptContent, els, el, div, content, voteData, popUpWidth; var res = ""; var loadwheelsrc = "data:image/gif;base64,R0lGODlhEAAQAPYAAP///wAAANTU1JSUlGBgYEBAQERERG5ubqKiotzc3KSkpCQkJCgoKDAwMDY2Nj4+Pmpqarq6uhwcHHJycuzs7O7u7sLCwoqKilBQUF5eXr6+vtDQ0Do6OhYWFoyMjKqqqlxcXHx8fOLi4oaGhg4ODmhoaJycnGZmZra2tkZGRgoKCrCwsJaWlhgYGAYGBujo6PT09Hh4eISEhPb29oKCgqioqPr6+vz8/MDAwMrKyvj4+NbW1q6urvDw8NLS0uTk5N7e3s7OzsbGxry8vODg4NjY2PLy8tra2np6erS0tLKyskxMTFJSUlpaWmJiYkJCQjw8PMTExHZ2djIyMurq6ioqKo6OjlhYWCwsLB4eHqCgoE5OThISEoiIiGRkZDQ0NMjIyMzMzObm5ri4uH5+fpKSkp6enlZ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iYRP4YACStxZRc0SBMyFoVEPAoWQDMzAgolEBqDRjg8O4ZKIBNAgkBjG5AAZVtsgj44VLdCanWCYUI3txUPS7xBx5AVDgazAjC3Q3ZeghUJv5B1cgOCNmI/1YUeWSkCgzNUFDODKydzCwqFNkYwOoIubnQIt244MzDC1q2DggIBACH5BAAKAAUALAAAAAAQABAAAAeJgACCg4SFhTBAOSgrEUEUhgBUQThjSh8IcQo+hRUbYEdUNjoiGlZWQYM2QD4vhkI0ZWKCPQmtkG9SEYJURDOQAD4HaLuyv0ZeB4IVj8ZNJ4IwRje/QkxkgjYz05BdamyDN9uFJg9OR4YEK1RUYzFTT0qGdnduXC1Zchg8kEEjaQsMzpTZ8avgoEAAIfkEAAoABgAsAAAAABAAEAAAB4iAAIKDhIWFNz0/Oz47IjCGADpURAkCQUI4USKFNhUvFTMANxU7KElAhDA9OoZHH0oVgjczrJBRZkGyNpCCRCw8vIUzHmXBhDM0HoIGLsCQAjEmgjIqXrxaBxGCGw5cF4Y8TnybglprLXhjFBUWVnpeOIUIT3lydg4PantDz2UZDwYOIEhgzFggACH5BAAKAAcALAAAAAAQABAAAAeLgACCg4SFhjc6RhUVRjaGgzYzRhRiREQ9hSaGOhRFOxSDQQ0uj1RBPjOCIypOjwAJFkSCSyQrrhRDOYILXFSuNkpjggwtvo86H7YAZ1korkRaEYJlC3WuESxBggJLWHGGFhcIxgBvUHQyUT1GQWwhFxuFKyBPakxNXgceYY9HCDEZTlxA8cOVwUGBAAA7AAAAAAAAAAAA"; function popUp(message, width, height, reload) { reload = reload || false; width = width || 200; height = height || 200; var body = document.getElementsByTagName('body')[0]; var masterDiv = document.getElementById('messagePopup'); if (masterDiv) { body.removeChild(masterDiv); } marginH = Math.ceil(parseFloat(width) / 2.00); marginV = Math.ceil(parseFloat(height) / 2.00); masterDiv = document.createElement('div'); masterDiv.id = "messagePopup"; masterDiv.style.position = "absolute"; masterDiv.style.left = "50%"; masterDiv.style.top = "50%"; masterDiv.style.width = width + "px"; masterDiv.style.height = height + "px"; masterDiv.style.backgroundColor = "#fff"; masterDiv.style.padding = "0px"; masterDiv.style.marginLeft = "-" + marginH + "px"; masterDiv.style.marginTop = "-" + marginV + "px"; masterDiv.style.border = "2px solid #333"; masterDiv.style.borderRadius = "10px"; masterDiv.style.boxShadow = "0 2px 6px rgba(102, 0, 0, 0.5)"; masterDiv.style.zIndex = "99"; masterDiv.style.padding = "5px"; var closeDiv = document.createElement('div'); closeDiv.style.backgroundColor = "#333"; closeDiv.style.height = "15px"; closeDiv.style.color = "#fff"; closeDiv.style.fontWeight = "bold"; closeDiv.style.padding = "2px"; closeDiv.style.paddingBottom = "4px"; closeDiv.style.textAlign = "right"; closeDiv.innerHTML = "[X]"; closeDiv.onmouseover = function () { this.style.cursor = 'pointer' }; closeDiv.onclick = function () { this.parentNode.style.display = 'none'; if (reload) { window.location.href = window.location.href; } }; var contentDiv = document.createElement('div'); contentDivHeight = height - 30; //10px for the closeDiv and 10px for the padding contentDiv.style.padding = "5px"; contentDiv.style.height = contentDivHeight + "px"; contentDiv.innerHTML = message; masterDiv.appendChild(closeDiv); masterDiv.appendChild(contentDiv); body.appendChild(masterDiv); } function getVoteInfo(){ if(!voteData){ getVotes(pageID, pageName); } else showVotes(); } function getVotes(pageID, pageName) { document.getElementById("loadwheel").style.visibility = 'visible'; return GM_xmlhttpRequest({ method: "POST", url: "http://ferryfm13.thirteen.axc.nl/scp/misc/callWikidot.php?c=rating&p=" + pageID + "&n=" + pageName, //url: "http://localhost/wikidot/callWikidot.php?c=rating&p=" + pageID + "&n=" + pageName, headers: {}, synchronous: true, onload: function(details){ voteData = JSON.parse(details.responseText); document.getElementById("loadwheel").style.visibility = 'hidden'; showVotes(); } }); } function showVotes() { var authorVoted = "no"; if (voteData.authorVoted == 1) { authorVoted = "yes"; } var res = ""; res += "<table cellpadding=\"1\" cellspacing=\"1\" style=\"border: 0;\" border=\"0\">"; res += "<tr><td>Real rating:</td><td>" + voteData.realRating + "</td></tr>"; res += "<tr><td>Upvotes:</td><td>" + voteData.upvotes + "</td></tr>"; res += "<tr><td>Downvotes:</td><td>" + voteData.downvotes + "</td></tr>"; res += "<tr><td>Votes from deleted accounts:</td><td>" + voteData.deletedAccounts + "</td></tr>"; res += "<tr><td>Total number of votes:</td><td>" + voteData.totalVotes + "</td></tr>"; res += "<tr><td>Double votes:</td><td>" + voteData.doubleVotes + "</td></tr>"; //res += "<tr><td>Votes from non-members:</td><td>" + voteData.nonMemberVotes + "</td></tr>"; res += "<tr><td>Author voted:</td><td>" + authorVoted + "</td></tr>"; res += "</table>"; popUp(res, 250, 165); } for (x = 0; x < scripts.length; x++) { if (scripts[x].innerHTML.indexOf('WIKIREQUEST.info.pageId') != -1) { scriptContent = scripts[x].innerHTML.split(";"); for (part of scriptContent) { pair = part.split('='); if (pair[0].trim() == "WIKIREQUEST.info.pageId") { pageID = pair[1].trim(); //console.log("Found pageID! Is: " + pageID); } if (pair[0].trim() == "WIKIREQUEST.info.requestPageName") { pageName = pair[1].trim(); //console.log("Found pageName! Is: " + pageName); } } } } //console.log("Adding listener to " + els.length + " elements."); div = document.createElement('div'); div.setAttribute('id', "showVoteInfoButton"); div.style.fontSize = "8pt"; div.style.marginTop = "-7px"; div.style.marginBottom = "5px"; div.innerHTML = "<a href=\"javascript:;\">+ Show more rating information</a>"; div.innerHTML += "<img src=\"" + loadwheelsrc + "\" id=\"loadwheel\"></img>"; div.addEventListener('click', function () { getVoteInfo(pageID, pageName); }, true); els = document.getElementsByClassName('page-rate-widget-box'); for (el of els){ el.parentNode.appendChild(div); } document.getElementById("loadwheel").style.visibility = 'hidden';