2013-12-23 16 views
0
提交關鍵字

我希望做一個Chrome擴展..我想一個選項頁面,您提交的關鍵字:HTML中進入的Javascript

<html> 
<head> 
    <title>Options</title> 
</head> 
<body> 
    Keyword:<input id="keyText" name="Keyword" type="text"> 
      <input name="Submit" type="submit" value="Submit"> 
</body> 
</html> 

這個JavaScript應該刷新微博,直到它找到一個關鍵詞然後點擊推文中的鏈接。 我想放在這個提交的關鍵字到Java腳本插入到第一VAR:

var shoeName = ""; 
var nikestore = "nikestore"; 
var closeFlag = "no"; 
var tFunction = "twitterScan()"; 
var tweet = new Array(); 
var tweetName = new Array(); 

function twitterScan() { 

for (var i = 0; i < 4; i++) { 
    tweetName[i] = document.getElementsByClassName("fullname js-action-profile-name show-popup-with-id")[0].innerHTML; 
    tweet[i] = document.getElementsByClassName("js-tweet-text")[i].innerHTML; 

} 


//if (document.getElementsByClassName("fullname js-action-profile-name show-popup-with-id")[0].innerHTML; 

if (tweet[0].match(shoeName) == shoeName) { 
    document.getElementsByClassName("twitter-timeline-link")[0].click(); 
    tFunction = "get outa here"; 
    shoeName = " 4444 4 456 7 8 456 7 345 7 345 345 3 1 1 133s "; //buffer to jump out of interval loop 

} 

else if (tweet[1].match(shoeName) == shoeName) { 
    document.getElementsByClassName("twitter-timeline-link")[1].click(); 
    tFunction = "get outa here"; 
    shoeName = " 4444 4 456 7 8 456 7 345 7 345 345 3 1 1 133s "; //buffer to jump out of interval loop 

} 

else if (tweet[2].match(shoeName) == shoeName) { 
    document.getElementsByClassName("twitter-timeline-link")[2].click(); 
    tFunction = "get outa here"; 
    shoeName = " 4444 4 456 7 8 456 7 345 7 345 345 3 1 1 133s "; //buffer to jump out of interval loop 

} 


else if (tweet[3].match(shoeName) == shoeName) { 
    document.getElementsByClassName("twitter-timeline-link")[3].click(); 
    tFunction = "get outa here"; 
    shoeName = " 4444 4 456 7 8 456 7 345 7 345 345 3 1 1 133s "; //buffer to jump out of interval loop 

} 


else { 
    location.reload(true); 
} 

setTimeout(tFunction, 700); 


} 

setTimeout(tFunction, 700); 

//setInterval("refreshPage()", 3000); 
//setTimeout("twitterScan()", 100); 
//setInterval(tFunction, 700); 
+0

html發佈完成了嗎?你目前面臨的問題是什麼?是可變數據不會來或某些功能行爲不當? –

+0

我想在html中提交的關鍵字被設置爲java腳本中的var shoeName – user2125877

+0

@ user2125877:我不確定爲什麼'document.getElementById('ketText')。val'不能在你的情況下工作,你能創建一個jsfiddle,http://jsfiddle.net,將檢查它 – dreamweiver

回答

0

HTML

Keyword:<input id="keyText" name="Keyword" type="text"> 
<input id="submit_button" name="Submit" type="Submit" value="Submit" onClick="javascript: twitterScan();"> 

JS

<script> 
var shoeName = ''; 
function twitterScan() { 
    shoeName = document.getElementById('keyText').value; 
    console.log("Iam called " + shoeName); 
} 
</script> 

檢查http://jsfiddle.net/raunakkathuria/5FDT3/

讓我知道如果這是你需要的

+0

對不起,我很困惑,你明白,有兩個單獨的文件,一個是html,另一個是.js – user2125877

+0

是的,我明白這就是爲什麼我在答案中添加了單獨的內容,什麼是混淆?您提供的JS代碼是加載到您的HTML頁面或其他地方?你如何調用js? –

+0

http://stackoverflow.com/questions/20769031/js-not-running-properly – user2125877