BSCF : sdgardne About Me - 10 pages

version 2

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name 		   BSCF : sdgardne About Me - 10 pages
// @namespace	   http://supportforums.blackberry.com/
// @description	version 2
// @include		http://supportforums.blackberry.com/t5/user/mobilemypostspage/page/*
// @include		https://supportforums.blackberry.com/t5/user/mobilemypostspage/page/*
// @version 0.0.1.20150820024916
// ==/UserScript==

/**
 * for each results page, reads the 10 threads and keeps the one with at least 1 New message
 * stored into MyThreadsList array.
**/
function condenseList(nodesSnapshot,_MyThreadsList,_pageNumber) {

	var nbrSpans = nodesSnapshot.snapshotLength;
	var myRow=document.createElement('tr');
	if (0!=nbrSpans) {
		var z=0 // when 0 then the HR has not been added yet
	
		for ( var i=0 ; i < nbrSpans ; i++ ) {
			var myCommenter=nodesSnapshot.snapshotItem(i);
			if (-1==myCommenter.textContent.indexOf(' (0 New)')) {
				// thread has at least 1 New message.
				
				if (0==z) {
					z=1;
					// on ajoute un hr
					var mySeperator=document.createElement('tr');
						var mytd1 = document.createElement('td');
							mytd1.appendChild(document.createTextNode('P'+_pageNumber));
						var mytd2 = document.createElement('td');
							mytd2.appendChild(document.createElement('hr'));
						var mytd3 = document.createElement('td');
						mySeperator.appendChild(mytd1);
						mySeperator.appendChild(mytd2);
						mySeperator.appendChild(mytd3);
					_MyThreadsList.push(mySeperator);
				} // end if
				
				myRow = myCommenter.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
				var dupRow = myRow.cloneNode(true);
				_MyThreadsList.push(dupRow);
				// le TR de l'idem
			} // end if
		} // end for
	} // end if

} // end function condenseList()

/** read last 10 pages
 * keeps threads with at least 1 New message.
**/
function fetchAndCondense(_MyThreadsList) {
	for ( var i=1 ; i<=10 ; i++ ) {
		var ficheURL = 'http://supportforums.blackberry.com/t5/user/mobilemypostspage/page/'+i;
		var xmlhttp;
		xmlhttp=new XMLHttpRequest();
		xmlhttp.open('GET',ficheURL,false);
		xmlhttp.send();
		var doc = document.implementation.createHTMLDocument('example');
		doc.documentElement.innerHTML = xmlhttp.responseText;
		var nodesSnapshot = doc.evaluate(
			  '//a[starts-with(@id, "threadReplies")]'
			, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
		);
		condenseList(nodesSnapshot,_MyThreadsList,i);
	} // end for
} // end function fetchAndCondense()

/**
 * main function
**/
window.xdx = function() {

	// hides the other table
	document.getElementsByTagName('table')[0].setAttribute('style','display: none;');

	var MyThreadsList= new Array();
	fetchAndCondense(MyThreadsList);
	
	// displays the unread list
	var myTable = document.createElement('table');
	myTable.setAttribute('style','border: solid red 1px');
	myTable.setAttribute('class','lia-list-wide');
	myTable.setAttribute('id','xdxNewMessages');
	for (var j=0 ; j<MyThreadsList.length ; j++) {
		myTable.appendChild(MyThreadsList[j]);
	} // end for
	document.getElementsByTagName('table')[0].parentNode.appendChild(myTable);
	
} // end xdx()

xdx();