Usuário:Higor Douglas/Vigiar mudanças recentes.js
Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
- Opera: Pressione Ctrl-F5.
//Veja a documentação [[Usuário:Higor Douglas/Vigiar mudanças recentes]]
var rcp_http;
var rcp_enabled;
var rcp_num_pages;
var rcp_refresh;
$( rcp_init );
/* initalise */
function rcp_init() {
if(rcp_enabled == null) {
rcp_enabled = false;
}
if(rcp_num_pages == null) {
rcp_num_pages = 10;
}
if(rcp_refresh == null) {
rcp_refresh = 5;
}
if (rcp_num_pages > 50) {
rcp_num_pages = 50;
}
if (rcp_num_pages < 1) {
rcp_num_pages = 1;
}
if (rcp_refresh < 2) {
rcp_refresh = 2;
}
if (document.cookie.length > 0) {
var c_start = document.cookie.indexOf("rcp_show_box=");
if (c_start != -1) {
c_start = c_start + 13;
var c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
if (document.cookie.substring(c_start, c_end) == "yes") {
rcp_enabled = true;
} else {
rcp_enabled = false;
}
}
}
if (rcp_enabled == true) {
rcp_ajax_request();
} else {
rcp_draw_disabled_box();
}
}
/* init ajax */
function rcp_create_request() {
try {
rcp_http = new XMLHttpRequest();
} catch (e) {
try {
rcp_http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
rcp_http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
rcp_http.onreadystatechange = function() {
if(rcp_http.readyState == 4) rcp_ajax_response();
}
return true;
}
/* make a request */
function rcp_ajax_request() {
if (rcp_enabled == false) return;
var cur_box = document.getElementById('p-recentchanges');
if (cur_box != null) {
cur_box.firstChild.firstChild.data = 'Mudanças recentes (...)';
}
if (rcp_create_request () == false) {
if (cur_box != null) {
cur_box.firstChild.firstChild.data = 'Mudanças recentes (Error)';
} else {
alert ("Parece haver um problema usando o script Vigiar mudanças recentes");
}
}
rcp_http.open("GET", "http://pt.wikipedia.org/w/api.php?action=query&list=recentchanges&format=xml&rcnamespace=0&rcshow=!bot&rcshow=!minor&rclimit=" + rcp_num_pages, true);
rcp_http.send(null);
}
/* we have received a response */
function rcp_ajax_response() {
var items = rcp_http.responseXML.getElementsByTagName('rc');
var link_div = document.createElement('div');
link_div.className = 'pBody';
var list = document.createElement('ul');
link_div.appendChild(list);
for (var i = 0; i < items.length; i++) {
var item_name = items[i].getAttribute('title');
var item_url = 'http://pt.wikipedia.org/w/index.php?diff=cur&oldid=prev&title=' + escape(item_name);
a = document.createElement('a');
a.setAttribute('href', item_url);
a.appendChild(document.createTextNode(item_name));
var li = document.createElement('li');
li.appendChild(a);
list.appendChild(li);
}
var div = document.createElement('div');
div.setAttribute('id', 'p-recentchanges');
div.className = 'portlet';
var heading = document.createElement('h5');
heading.appendChild(document.createTextNode('Mudanças recentes'));
div.appendChild(heading);
div.appendChild(link_div);
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
p.style.textAlign = 'right';
a = document.createElement('a');
a.appendChild(document.createTextNode('Esconder'));
a.onclick = rcp_disable_box;
p.appendChild(a);
link_div.appendChild(p);
var old_div = document.getElementById('p-recentchanges');
var side_col = document.getElementById('column-one');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-search');
side_col.insertBefore(div, node);
}
setTimeout("rcp_ajax_request()", rcp_refresh * 1000);
}
function rcp_disable_box() {
rcp_enabled = false;
rcp_draw_disabled_box();
document.cookie = "rcp_show_box=no; path=/";
}
function rcp_enable_box() {
rcp_enabled = true;
document.cookie = "rcp_show_box=yes; path=/";
rcp_ajax_request();
}
function rcp_draw_disabled_box() {
var link_div = document.createElement('div');
link_div.className = 'pBody';
var div = document.createElement('div');
div.setAttribute('id', 'p-recentchanges');
div.className = 'portlet';
var heading = document.createElement('h5');
heading.appendChild(document.createTextNode('Mudanças recentes'));
div.appendChild(heading);
div.appendChild(link_div);
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
var a = document.createElement('a');
a.appendChild(document.createTextNode('Expandir'));
a.onclick = rcp_enable_box;
p.appendChild(a);
link_div.appendChild(p);
var old_div = document.getElementById('p-recentchanges');
var side_col = document.getElementById('column-one');
if (old_div != null) {
side_col.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-search');
side_col.insertBefore(div, node);
}
}