Created
November 7, 2011 23:57
-
-
Save ericdstrom/1346599 to your computer and use it in GitHub Desktop.
wikipedia challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Installation - | |
This javascript (code.js) is meant to be put straight into your personal vector.js file. | |
Operation - | |
The script checks every 30 seconds to see if the page that you are currently reading has been changed. If so, a small icon will appear at the bottom left of your screen alerting you to the revision. When clicked, the changes will be inserted into the page and will be highlighted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript Document | |
var timeAt; | |
var startTime; | |
var check; | |
var pagecode = $(".mw-content-ltr").html(); | |
var pagebreak = pagecode.split(/(<p>|<h2>|<table>)/); | |
function loadchange(){ | |
$("#wikichange").fadeOut(); | |
var title = location.href; | |
var lastslash = title.lastIndexOf("/") + 1; | |
title = title.substring(lastslash); | |
$.get("http://en.wikipedia.org/w/index.php", { action: "render", title: title }, | |
function(data){ | |
var newpagecode = data; | |
var newpagebreak = data.split(/(<p>|<h2>|<table>)/); | |
var pagebreaktest = new Array(); | |
for(i=0;i<newpagebreak.length;i++){ | |
pagebreaktest[i] = "1"; | |
if(jQuery.inArray(newpagebreak[i], pagebreak) > -1){ | |
pagebreaktest[i] = "0"; | |
} | |
} | |
var newpage = ""; | |
for(i=0;i<newpagebreak.length;i++){ | |
if(pagebreaktest[i] == "1"){ | |
newpage = newpage + "<span class='newtext' style='display:inline; background:#f6f6f6; border:#d8d8d8 1px solid; border-radius:3px; margin:0px; padding:2px;' >" + newpagebreak[i] + "</span>"; | |
} | |
if(pagebreaktest[i] == "0"){ | |
newpage = newpage + newpagebreak[i]; | |
} | |
} | |
$(".mw-content-ltr").html(newpage); | |
clearTimeout(timer); | |
}); | |
} | |
function checkChange(){ | |
var title = location.href; | |
var lastslash = title.lastIndexOf("/") + 1; | |
title = title.substring(lastslash); | |
$.get("http://en.wikipedia.org/w/api.php", { action: "query", prop: "revisions", titles: title, rvlimit: "1", rvprop: "timestamp", format: "xml" }, | |
function(data){ | |
timeAt = data.indexOf("<rev timestamp="); | |
timeAt = timeAt + 16; | |
timeAt = data.substr(timeAt, 20); | |
check = $("#wikichange").attr("class"); | |
if(timeAt != check){ | |
$("#wikichange").fadeIn(); | |
clearTimeout(timer); | |
} | |
}, "text"); | |
var timer = setTimeout("checkChange()",30000); | |
} | |
$(document).ready(function(){ | |
$("#wikichange").data("lastchange", "hello"); | |
var title = location.href; | |
var lastslash = title.lastIndexOf("/") + 1; | |
title = title.substring(lastslash); | |
//get last edit timestamp | |
$.get("http://en.wikipedia.org/w/api.php", { action: "query", prop: "revisions", titles: title, rvlimit: "1", rvprop: "timestamp", format: "xml" }, | |
function(data){ | |
startTime = data.indexOf("<rev timestamp="); | |
startTime = startTime + 16; | |
startTime = data.substr(startTime, 20); | |
var divstring = "<div onclick='loadchange()' id='wikichange' class='" + startTime + "' style='height:40px; vertical-align:center; background:#323232; position:absolute; bottom:0px; left:0px; display:none; z-index:10000; background:#fff; border:#d8d8d8 2px solid; padding:3px; color:#000; font-size:14px;'>Changes have been made to this article. Click to see.</div>"; | |
$("body").prepend(divstring); | |
}, "text"); | |
var timer = setTimeout("checkChange()",30000); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright (C) 2011 Eric Strom <ericdstrom@gmail.com> | |
This program is free software; you can redistribute it and/or | |
modify it under the terms of the GNU General Public License | |
as published by the Free Software Foundation; either version 2 | |
of the License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to | |
Free Software Foundation, Inc. | |
51 Franklin Street, Fifth Floor | |
Boston, MA 02110-1301, USA. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment