summaryrefslogtreecommitdiff
path: root/post_fsd_wiki.phantomjs
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2018-01-21 08:06:02 -0500
committerbill-auger <mr.j.spam.me@gmail.com>2018-02-13 13:29:34 -0500
commitaacebcc1887bd5a060e6737bc818ee10e36f67da (patch)
tree94cb603199ce91aeb03e2bbcd3167429d21916ac /post_fsd_wiki.phantomjs
parent3423c9098144d8a0091e1f18b938dc4c8dd44e74 (diff)
squashme wiki
Diffstat (limited to 'post_fsd_wiki.phantomjs')
-rw-r--r--post_fsd_wiki.phantomjs85
1 files changed, 16 insertions, 69 deletions
diff --git a/post_fsd_wiki.phantomjs b/post_fsd_wiki.phantomjs
index 7c18925..f6ee73f 100644
--- a/post_fsd_wiki.phantomjs
+++ b/post_fsd_wiki.phantomjs
@@ -96,7 +96,7 @@ function LoadLoginPage()
function SubmitLogin()
{
EvalQuitOnErr(Page.evaluate(function(login_input_id , pass_input_id , submit_input_id ,
- wiki_login , wiki_pass )
+ wiki_login , wiki_pass )
{
var login_input = document.getElementById(login_input_id ) ;
var pass_input = document.getElementById(pass_input_id ) ;
@@ -114,7 +114,10 @@ function SubmitLogin()
login_form.submit() ;
+ return '' ;
} , LOGIN_IMPUT_ID , PASS_IMPUT_ID , LOGIN_SUBMIT_IMPUT_ID , WIKI_LOGIN , WIKI_PASS)) ;
+
+ IsReady = true ;
}
function VerifyLogin()
@@ -128,8 +131,10 @@ function VerifyLogin()
username != wiki_login.toLowerCase() )
return "ERROR: login failed" ;
- console.info("signed in as: " + username) ;
+ console.info("signed in as: " + username) ; return '' ;
} , USERNAME_LI_ID , WIKI_LOGIN)) ;
+
+ IsReady = true ;
}
function LoadWikiData()
@@ -148,8 +153,6 @@ function LoadEditPage()
function SubmitEdit()
{
-if (DEBUG) DBG("in") ;
-
var page_title = WikiPage[PACKAGE_NAME_KEY] ;
var wiki_text = WikiPage[DESCRIPTION_KEY ] ;
@@ -192,62 +195,11 @@ if (DEBUG) DBG("in") ;
// DBG("returned post_wiki_text=" + post_wiki_text) ;
- if (!post_wiki_text) { LOG("wiki text has not changed - skipping") ; NextPage() ; return ; }
-
-/*
-console.log("edit_form.action=" + edit_form.action) ;
-var edit_form_fields = edit_form.getElementsByTagName('input') ;
-for (child_node_n in edit_form_fields)
-{
- if (!edit_form.hasOwnProperty(child_node_n)) continue ;
-
- var child_node = edit_form_fields[child_node_n] ;
- var field_key = child_node.name ;
- var field_value = child_node.value ;
-
- if (child_node.type != 'hidden' || !field_key || !field_value) continue ;
-
-// field_key=wpStarttime field_value=20180121060903
-// field_key=wpEdittime field_value=20180121060903
-// field_key=wpAutoSummary field_value=d41d8cd98f00b204e9800998ecf8427e
-// field_key=oldid field_value=0
-// field_key=parentRevId field_value=0
-// field_key=format field_value=text/x-wiki
-// field_key=model field_value=wikitext
-// field_key='wpEditToken field_value=d70645952b36fc2f29c73a665bb3acf45a642e80+\'
-// field_key=wpUltimateParam field_value=1
-console.log("child_node=" + child_node + " field_key=" + field_key + " field_value=" + field_value) ;
-}
-*/
-/*
- var xhr = new XMLHttpRequest() ;
-var url = edit_form.action ;
- var params = "lorem=ipsum&name=binny" ;
- xhr.open('POST' , url , true) ;
- xhr.setRequestHeader('Content-type' , 'application/x-www-form-urlencoded') ;
-
- xhr.onreadystatechange = function()
- {
- if (xhr.readyState == 4 && xhr.status == 200)
- {
-console.log(xhr.responseText) ;
- }
- }) ;
- xhr.send(params) ;
-*/
-/*
- var post_body = 'wpTextbox1=' + post_wiki_text +
- '&wpSave=' + 'Save page' +
- '&wpEditToken=' + edit_token ;
- PostUrl(edit_form_action , post_body) ;
-*/
-if (DEBUG) DBG("out") ;
+ if (post_wiki_text == '') { LOG("wiki text has not changed - skipping") ; NextPage() ; }
}
function VerifyEdit()
{
-if (DEBUG) DBG("in") ;
-
var page_title = WikiPage[PACKAGE_NAME_KEY] ;
var wiki_text = WikiPage[DESCRIPTION_KEY ] ;
var expected_url = WIKI_BASE_URL + '/' + page_title ;
@@ -280,6 +232,7 @@ console.log("wiki_text_regex.test(existing_wiki_text)=" + wiki_text_regex.test(e
!wiki_text_div || wiki_text_div.nodeName != 'DIV' || !wiki_text_regex.test(existing_wiki_text))
return "ERROR: edit post failed" ;
+ return '' ;
} , WIKI_TITLE_H1_ID , WIKI_TEXT_DIV_ID , page_title , wiki_text)) ;
if (!err) LOG("successfully updated: " + page_title) ; NextPage() ;
@@ -296,7 +249,6 @@ function DefineStep(step_function , should_wait_for_pageload)
Steps.push(step_data) ;
}
-
function MainLoop()
{
if (DEBUG_VB) DBG("ShouldQuit=" + ShouldQuit + " IsReady=" + IsReady) ;
@@ -318,7 +270,7 @@ if (DEBUG_VB) DBG("ShouldQuit=" + ShouldQuit + " IsReady=" + IsReady) ;
function PumpMainLoop() { setTimeout(MainLoop , 250) ; }
-function ForceQuit(quit_msg) { ShouldQuit = quit_msg ; PumpMainLoop() ; }
+function ForceQuit(quit_msg) { ShouldQuit = quit_msg || 'script error' ; PumpMainLoop() ; }
function Done() { LOG("done") ; phantom.exit() ; LOG('') ; }
@@ -332,19 +284,14 @@ DBG("get_url=" + get_url) ;
Page.open(get_url , function(status) { if (status != 'success') ForceQuit("status: " + status) ; }) ;
}
-function PostUrl(post_url , post_body)
-{
-DBG("post_url=" + post_url) ;
-
- Page.open(post_url , 'POST' , post_body , function(status)
- {
- if (status != 'success') ForceQuit("status: " + status) ;
- }) ;
-}
-
function EvalQuitOnErr(result)
{
- if (typeof result == 'string' && !result.indexOf('ERROR:')) ForceQuit(result) ;
+// CAVEATS: this function is intended to handle the return value of 'Page.evaluate' callbacks
+// on success, the 'Page.evaluate' callback must return a string not matching /^ERROR:.*/
+// the Step function must set IsReady to true sometime after this function returns
+// unless it is waiting for a page load, in which case, 'Page.onLoadFinished' will flag it
+
+ if (typeof result != 'string' || !result.indexOf('ERROR:')) ForceQuit(result) ;
else IsReady = !ShouldWait ;
return result ;