Anonymous user
User talk:Badmadevil: Difference between revisions
m
→Not Implemented Tasks by Language: regexp version, remove unsed http.js
m (→Not Implemented Tasks by Language: minor edits) |
m (→Not Implemented Tasks by Language: regexp version, remove unsed http.js) |
||
Line 9:
== Not Implemented Tasks by Language ==
Hello. IIRC, it has been mentioned an idea to display a page of tasks not implemented by a specific language (It is from [[User:IanOsgood|Ian Osgood]]'s [[Rosetta_Code:Wiki_Wishlist|wishlist]]), it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using client-side javascript. It use xmlhttprequest to get the contents of Solutions_by_Programming_Task & the language specified page that contains tasks such language has been completed, then by
{||-
| style="height:36em;float:left;clear:both;overflow:auto;" |
Line 21 ⟶ 17:
<!--script src="http.js"></script-->
<script>
<javascript>/**
** C o n f i g
**/
// javascript's XMLHTTPRequest doesn't allow cross site request,
// so this script's location's host has to be same as the Category pages.
// the prefix change to 'http://rosettacode.org/wiki/Category:' should be ok
//var mySitePrefix = 'http://
var mySitePrefix = 'http://rosettacode.org/wiki/Category:' ;
// set to
// C# etc. pages.
//var usesafeurl = false ;
// this is maximum length of '<a .. /a>' plus <li></li>, Capital Heading's HTML
// sources in next link capture string in o.getlink function. Currently, it is
// about 340 (found by trail and error).
// Modify this value if longer name of new task is added.
var preFetchLen = 400 ;
// To test in a loacl web server (eg. http://localhost):
// 1.mkdir wiki in root dir of localhost,
Line 68 ⟶ 42:
// localhost/wiki/<CATEGORYNAME>/index.htm,
// 2.<CATEGORYNAME> should at leat include Solutions_by_Programming_Task &
// Solutions_by_Programming_Language, then include some other languages
// categories, eg. C, Java, Python, etc. to start testing.
// 3.place http.js where this html can located,
// 4.no query string should be in url of this html,
var working = "<none>" ;
var NA = "N/A" ;
function Page(url, ID) {
var o = new Object ;
Line 81 ⟶ 56:
o.cnt = 0 ;
o.htm = NA ;
o.lnk = new Array() ;
o.request = function() { HTTP.getText(o.url, o.setHtm)}
// NOTE:
// GLOBAL RegExp is not use, for I can't handle it right, or the performance is bad.
o.setHtm = function(txt) {
var head = 0 ;
var tail = 0 ;
working = o.url + '<br />';
head = txt.search(o.ID + '">') ;
if(head >= 0) {
tail = txt.search('printfooter') ;
if(tail >= 0) {
o.htm = txt.slice(head + o.ID.length + 2,tail - 12) ;
o.getlink() ;
}
}
}
o.getlink = function() {
if(o.htm != NA) {
var
var head
var tail = 0. ;
var htmlen = o.htm.length ;
while(start >= 0 &&
var part = o.htm.slice(start, Math.min(start + preFetchLen, htmlen)) ;
head = part.search('<a') ;
if(head >= 0) {
tail = part.search('a>') ;
if(tail >= 0) {
var mh = part.slice(head, tail).match(re) ;
if(mh) {
o.lnk[mh[1]] = mh[2] ;
o.cnt++ ;
}
}
}
if(head < 0 || tail < 0) start = -1 ; else start += (tail + 1) ;
}
}
Line 109 ⟶ 105:
var rosettaUrl = 'http://rosettacode.org'
var langID = getLangID() ;
var langurl = langID != NA && usesafeurl ? safeurl() : mySitePrefix + langID ;
var task = Page(mySitePrefix + 'Solutions_by_Programming_Task', "mw-pages") ;
Line 116 ⟶ 111:
var tasklist ;
var langlist ;
var timeoutCnt =
var count = 0 ;
function getLangID() {
var langid = window.location.search.slice(1) ;
if(langid.length == 0) return NA ;
return langid ;
}
function safeurl(langname) {
if(!langname) langname = langID ;
return rosettaUrl + '/w/index.php?title=' + langname ;
}
function process() {
tasklist = document.getElementById("tasklist") ;
Line 146 ⟶ 141:
function waitLoad() {
timeoutCnt-- ;
// tasklist.innerHTML =
//
tasklist.innerHTML = '...loading ' + working + 'timeout in ' + timeoutCnt + ' sec...' ;
if(timeoutCnt > 0 &&
((langID != NA && lang.htm == NA) || task.htm == NA || list.htm == NA))
return setTimeout(waitLoad,1000) ;
if(langID == NA)
return failLoad() ;
if(timeoutCnt <= 0)
return failLoad() ;
if(task.cnt == 0 || list.cnt == 0 || lang.cnt == 0) return failLoad() ;
doParse() ;
}
Line 162 ⟶ 159:
if(langID == NA)
errmsg += 'Language ID not known.' ;
else
errmsg += 'Error Page - url : ' +
alink(scriptUrl + '?' + langID,langID,langID, true) ;
}
errmsg += '<br />' ;
with(lang) if(htm == NA)
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
with(list) if(htm == NA)
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
with(task) if(htm == NA)
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
tasklist.innerHTML = errmsg + makeStatus() ;
var taskdom = ""
if(task.cnt > 0 && lang.cnt > 0) taskdom = makeTask() ;
try {
if(taskdom == "") taskdom = task.
} catch(e) {
taskdom = "" ;
}
if(taskdom != "")
taskdom = makeMenu() + '<br />' + taskdom ;
else
taskdom = makeMenu() + '<br />Tasks Page not found/load.' ;
var listdom = "" ;
if(list.cnt >0) listdom = makeList();
try {
if(listdom == "") listdom = list.
} catch(e) {
listdom = "" ;
}
if(listdom != "")
listdom = '<hr />' + makeReturn() + '<hr />' + listdom ;
else
listdom = '<hr />' + makeReturn() + '<hr />Languages List Page not found/load.' ;
langlist.innerHTML = taskdom + listdom ;
Line 201 ⟶ 198:
function doParse() {
var taskdom = makeTask() ;
tasklist.innerHTML = makeMenu() + '<h2>Tasks not implemented by ' + alink(rosettaUrl +
'/wiki/' + langID, langID,langID, true) + '</h2><hr /><br />There are <strong>' +
count + '</strong> not implemented tasks out of <strong>' + task.cnt +
'</strong> total tasks. ' + '(' + lang.cnt
' completed tasks, implementations & puzzles etc.)<br />' + taskdom ;
langlist.innerHTML = makeReturn() + '<hr /
}
function alink(url, tip, txt, normalsize, nameanchor) {
var
extra += nameanchor ? ' name="' + nameanchor + '"' : "" ;
return '<a href="' + url + '" title="' + tip + '"' +
unescape(txt) + '</a>' ;
}
function makeMenu() {
var backLink ;
if(langID == NA) {
backLink = alink(list.url, "Solution by Languages",
'Return to Category : Solution by Languages') ;
} else {
backLink = alink(safeurl(), safeurl(), 'Return to Category : ' + langID)
}
return alink('#' + tx, tx, 'Select other languages
' | ' + backLink + '<hr />' ;
}
function makeReturn() {
// return alink('#' + tx, tx, 'TOP', true, 'otherlanguages') +
// ' | ' + makeStatus() ;
return alink('#' + tx, tx, 'TOP', true, 'otherlanguages') ;
}
function makeStatus() {
return '(total / langs / taskss) - pages length : ' +
task.htm.length + ' / ' + list.htm.length + ' / ' +
lang.htm.length + ' | link count : ' + task.cnt +
' / ' + list.cnt + ' / ' + lang.cnt ;
}
function makeList() {
var backLink ;
if(langID == NA) {
backLink = alink(list.url, "Solution by Languages",
'※') ;
} else {
backLink = alink(safeurl(), langID, '※')
}
if(list.cnt == 0) return "" ;
var html = '<
'"font-size:78%;">click ' + backLink + ' to visit Normal Category' +
'</span>) :</h3><table width="100%"><tr>' ;
splitCnt = 0 ;
var cols = 6 ;
var wd = 'width="' + Math.floor(100/cols) + '%"' ;
for(i in list.lnk)
if(list.lnk[i]){
var txt = list.lnk[i] ;
var uri = i ;
var langTag = txt.split(':') ;
var langUri = uri.split(':') ;
if(langTag.length == 2) {
if(splitCnt >= cols) {
Line 268 ⟶ 276:
var heading ;
for(i in task.lnk)
if(!lang.lnk[i]) count++ ;
if(count > 0) {
var splitCnt = 0 ;
Line 279 ⟶ 287:
capital = txt.charAt(0) ;
if(splitCnt*3 > count + 2) {
splitCnt = 0 ;
html += '</ul></td><td valign="top" width="33%">'
if(capital == heading)
Line 289 ⟶ 297:
html += '<h3>' + capital + '<h3><ul>'
}
html += '<li>' + alink(lnk, txt, txt) + '</li>' ;
}
html += '</ul>' ;
} else
return "" ;
html += '</td></tr></table><br />' ;
return html ;
}</javascript>
</script>
<!-- from http://examples.oreilly.com/jscript5/ , unused parts removed-->
<script>
<javascript>/**
Line 306 ⟶ 314:
* by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN: 0596101996)
*/
// Make sure we haven't already been loaded
var HTTP;
if (HTTP && (typeof HTTP != "object" || HTTP.NAME))
throw new Error("Namespace 'HTTP' already exists");
// Create our namespace, and specify some meta-information
HTTP = {};
HTTP.NAME = "HTTP"; // The name of this namespace
HTTP.VERSION = 1.0; // The version of this namespace
// This is a list of XMLHttpRequest creation factory functions to try
HTTP._factories = [
Line 323 ⟶ 331:
function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
];
// When we find a factory that works, store it here
HTTP._factory = null;
/**
* Create and return a new XMLHttpRequest object.
*
* The first time we're called, try the list of factory functions until
* we find one that returns a nonnull value and does not throw an
Line 335 ⟶ 343:
*/
HTTP.newRequest = function() {
if (HTTP._factory != null)
return HTTP._factory();
for(var i = 0; i < HTTP._factories.length; i++) {
try {
Line 351 ⟶ 359:
}
}
// If we get here, none of the factory candidates succeeded,
// so throw an exception now and for all future calls.
Line 359 ⟶ 367:
HTTP._factory(); // Throw an error
}
/**
* Use XMLHttpRequest to fetch the contents of the specified URL using
* an HTTP GET request. When the response arrives, pass it (as plain
* text) to the specified callback function.
*
* This function does not block and has no return value.
*/
Line 375 ⟶ 383:
request.open("GET", url);
request.send(null);
};</javascript>
</script>
<body onLoad="process();" >
Line 633 ⟶ 396:
</html>
|}
Hope it can be a temporary solution. -- [[User:Badmadevil|badmadevil]]
|