2016-01-21 49 views
0

我想做一個隨機發布的小部件工作在我的博客(博客),但瀏覽器不斷給我一個錯誤,說該腳本沒有響應: 「腳本上此頁面可能正忙,或者它可能已停止響應,您現在可以停止腳本,在調試器中打開腳本,或者讓腳本繼續隨機帖子部件腳本不工作在博主

腳本:。http://testeshoon.blogspot.pt/:4792

腳本來與模板。 已經嘗試從網絡上的其他腳本,但他們都做同樣的事情。 我試圖解決這個過去兩天,但無法弄清楚問題是什麼。

任何人都可以幫助我嗎? 真的需要這個工作,至少,在2個部件。

爲最近的帖子嘗試腳本,那些工作很好,但隨機的腳本沒有。

<ul id='random-posts'> 
 
\t <script type='text/javaScript'> 
 
\t \t var rdp_numposts = 2; 
 
\t \t var rdp_snippet_length = 100; 
 
\t \t var rdp_info = 'yes'; 
 
\t \t var rdp_comment = 'Comments'; 
 
\t \t var rdp_disable = 'Comments Disabled'; 
 
\t \t var rdp_current = []; 
 
\t \t var rdp_total_posts = 0; 
 
\t \t var rdp_current = new Array(rdp_numposts); 
 

 
\t \t function totalposts(json) { 
 
\t \t \t rdp_total_posts = json.feed.openSearch$totalResults.$t 
 
\t \t } 
 
\t \t document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default/-/noticias?alt=json-in-script&max-results=0&callback=totalposts\"><\/script>'); 
 

 
\t \t function getvalue() { 
 
\t \t \t for (var i = 0; i < rdp_numposts; i++) { 
 
\t \t \t \t var found = false; 
 
\t \t \t \t var rndValue = get_random(); 
 
\t \t \t \t for (var j = 0; j < rdp_current.length; j++) { 
 
\t \t \t \t \t if (rdp_current[j] == rndValue) { 
 
\t \t \t \t \t \t found = true; 
 
\t \t \t \t \t \t break 
 
\t \t \t \t \t } 
 
\t \t \t \t }; 
 
\t \t \t \t if (found) { 
 
\t \t \t \t \t i-- 
 
\t \t \t \t } else { 
 
\t \t \t \t \t rdp_current[i] = rndValue 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t }; 
 

 
\t \t function get_random() { 
 
\t \t \t var ranNum = 1 + Math.round(Math.random() * (rdp_total_posts - 1)); 
 
\t \t \t return ranNum 
 
\t \t }; 
 
\t </script> 
 
\t <script type='text/javaScript'> 
 
\t \t var _0x3eb4=["\x65\x6E\x74\x72\x79","\x66\x65\x65\x64","\x24\x74","\x74\x69\x74\x6C\x65","\x63\x6F\x6E\x74\x65\x6E\x74","\x73\x75\x6D\x6D\x61\x72\x79","","\x72\x65\x70\x6C\x61\x63\x65","\x6C\x65\x6E\x67\x74\x68","\x73\x75\x62\x73\x74\x72\x69\x6E\x67","\x20","\x6C\x61\x73\x74\x49\x6E\x64\x65\x78\x4F\x66","\x26\x23\x31\x33\x33\x3B","\x6C\x69\x6E\x6B","\x74\x68\x72\x24\x74\x6F\x74\x61\x6C","\x72\x65\x6C","\x61\x6C\x74\x65\x72\x6E\x61\x74\x65","\x68\x72\x65\x66","\x70\x75\x62\x6C\x69\x73\x68\x65\x64","\x6D\x65\x64\x69\x61\x24\x74\x68\x75\x6D\x62\x6E\x61\x69\x6C","\x75\x72\x6C","\x68\x74\x74\x70\x3A\x2F\x2F\x33\x2E\x62\x70\x2E\x62\x6C\x6F\x67\x73\x70\x6F\x74\x2E\x63\x6F\x6D\x2F\x2D\x35\x53\x6F\x56\x65\x31\x4B\x36\x4A\x53\x6B\x2F\x55\x74\x6C\x30\x4F\x4F\x6D\x75\x63\x41\x49\x2F\x41\x41\x41\x41\x41\x41\x41\x41\x46\x36\x45\x2F\x68\x51\x67\x68\x67\x44\x5F\x45\x4A\x64\x51\x2F\x73\x31\x36\x30\x30\x2F\x6E\x6F\x5F\x74\x68\x75\x6D\x62\x2E\x70\x6E\x67","\x3C\x6C\x69\x3E","\x77\x72\x69\x74\x65","\x3C\x61\x20\x68\x72\x65\x66\x3D\x22","\x22\x20\x72\x65\x6C\x3D\x22\x6E\x6F\x66\x6F\x6C\x6C\x6F\x77\x22\x3E\x3C\x69\x6D\x67\x20\x61\x6C\x74\x3D\x22","\x22\x20\x73\x72\x63\x3D\x22","\x22\x2F\x3E\x3C\x2F\x61\x3E","\x3C\x64\x69\x76\x3E\x3C\x61\x20\x68\x72\x65\x66\x3D\x22","\x22\x20\x72\x65\x6C\x3D\x22\x6E\x6F\x66\x6F\x6C\x6C\x6F\x77\x22\x20\x74\x69\x74\x6C\x65\x3D\x22","\x22\x3E","\x3C\x2F\x61\x3E\x3C\x2F\x64\x69\x76\x3E","\x79\x65\x73","\x3C\x73\x70\x61\x6E\x3E\x3C\x64\x69\x76\x20\x20\x63\x6C\x61\x73\x73\x3D\x22\x72\x70\x2D\x69\x6E\x66\x6F\x22\x3E","\x2F","\x20\x2D\x20","\x3C\x2F\x64\x69\x76\x3E\x3C\x2F\x73\x70\x61\x6E\x3E","\x3C\x62\x72\x2F\x3E\x3C\x64\x69\x76\x20\x63\x6C\x61\x73\x73\x3D\x22\x72\x70\x2D\x73\x6E\x69\x70\x70\x65\x74\x22\x3E","\x3C\x2F\x64\x69\x76\x3E\x3C\x64\x69\x76\x20\x73\x74\x79\x6C\x65\x3D\x22\x63\x6C\x65\x61\x72\x3A\x62\x6F\x74\x68\x22\x3E\x3C\x2F\x64\x69\x76\x3E\x3C\x2F\x6C\x69\x3E","\x3C\x73\x63\x72\x69\x70\x74\x20\x74\x79\x70\x65\x3D\x22\x74\x65\x78\x74\x2F\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x22\x20\x73\x72\x63\x3D\x22\x2F\x66\x65\x65\x64\x73\x2F\x70\x6F\x73\x74\x73\x2F\x64\x65\x66\x61\x75\x6C\x74\x3F\x61\x6C\x74\x3D\x6A\x73\x6F\x6E\x2D\x69\x6E\x2D\x73\x63\x72\x69\x70\x74\x26\x73\x74\x61\x72\x74\x2D\x69\x6E\x64\x65\x78\x3D","\x26\x6D\x61\x78\x2D\x72\x65\x73\x75\x6C\x74\x73\x3D\x31\x26\x63\x61\x6C\x6C\x62\x61\x63\x6B\x3D\x72\x61\x6E\x64\x6F\x6D\x5F\x70\x6F\x73\x74\x73\x22\x3E\x3C\x2F\x73\x63\x72\x69\x70\x74\x3E"];function random_posts(_0x2f3cx2){for(var i=0;i<rdp_numposts;i++){var _0x2f3cx4=_0x2f3cx2[_0x3eb4[1]][_0x3eb4[0]][i];var _0x2f3cx5=_0x2f3cx4[_0x3eb4[3]][_0x3eb4[2]];if(_0x3eb4[4] in _0x2f3cx4){var _0x2f3cx6=_0x2f3cx4[_0x3eb4[4]][_0x3eb4[2]];} else {if(_0x3eb4[5] in _0x2f3cx4){var _0x2f3cx6=_0x2f3cx4[_0x3eb4[5]][_0x3eb4[2]];} else {var _0x2f3cx6=_0x3eb4[6];} ;} ;_0x2f3cx6=_0x2f3cx6[_0x3eb4[7]](/<[^>]*>/g,_0x3eb4[6]);if(_0x2f3cx6[_0x3eb4[8]]<rdp_snippet_length){var _0x2f3cx7=_0x2f3cx6;} else {_0x2f3cx6=_0x2f3cx6[_0x3eb4[9]](0,rdp_snippet_length);var _0x2f3cx8=_0x2f3cx6[_0x3eb4[11]](_0x3eb4[10]);_0x2f3cx7=_0x2f3cx6[_0x3eb4[9]](0,_0x2f3cx8)+_0x3eb4[12];} ;for(var _0x2f3cx9=0;_0x2f3cx9<_0x2f3cx4[_0x3eb4[13]][_0x3eb4[8]];_0x2f3cx9++){if(_0x3eb4[14] in _0x2f3cx4){var _0x2f3cxa=_0x2f3cx4[_0x3eb4[14]][_0x3eb4[2]]+_0x3eb4[10]+rdp_comment;} else {_0x2f3cxa=rdp_disable;} ;if(_0x2f3cx4[_0x3eb4[13]][_0x2f3cx9][_0x3eb4[15]]==_0x3eb4[16]){var _0x2f3cxb=_0x2f3cx4[_0x3eb4[13]][_0x2f3cx9][_0x3eb4[17]];var _0x2f3cxc=_0x2f3cx4[_0x3eb4[18]][_0x3eb4[2]];if(_0x3eb4[19] in _0x2f3cx4){var _0x2f3cxd=_0x2f3cx4[_0x3eb4[19]][_0x3eb4[20]];} else {_0x2f3cxd=_0x3eb4[21];} ;} ;} ;document[_0x3eb4[23]](_0x3eb4[22]);document[_0x3eb4[23]](_0x3eb4[24]+_0x2f3cxb+_0x3eb4[25]+_0x2f3cx5+_0x3eb4[26]+_0x2f3cxd+_0x3eb4[27]);document[_0x3eb4[23]](_0x3eb4[28]+_0x2f3cxb+_0x3eb4[29]+_0x2f3cx7+_0x3eb4[30]+_0x2f3cx5+_0x3eb4[31]);if(rdp_info==_0x3eb4[32]){document[_0x3eb4[23]](_0x3eb4[33]+_0x2f3cxc[_0x3eb4[9]](8,10)+_0x3eb4[34]+_0x2f3cxc[_0x3eb4[9]](5,7)+_0x3eb4[34]+_0x2f3cxc[_0x3eb4[9]](0,4)+_0x3eb4[35]+_0x2f3cxa)+_0x3eb4[36];} ;document[_0x3eb4[23]](_0x3eb4[37]+_0x2f3cx7+_0x3eb4[38]);} ;} ;getvalue();for(var i=0;i<rdp_numposts;i++){document[_0x3eb4[23]](_0x3eb4[39]+rdp_current[i]+_0x3eb4[40]);} ; 
 
\t </script> 
 
</ul>

+0

在for循環的第一行添加console.log(i)報告會發生什麼。您可以在瀏覽器的控制檯窗口中看到它的輸出。 – Glubus

+0

如果'rdp_total_posts'設置爲零,並且您在get_random函數中使用var varNum = 1 + Math.round(Math.random()*(rdp_total_posts - 1)),那麼結果不會是零或更少那麼零? – Dennis1679

+0

@ Dennis1679,不,它是非共享第三方腳本的回調。 –

回答

0

讓我們假設你想從n可能的數字k個不同的數字(隨機指標後)。這裏是一個實施

function getRandomSubset(n, k) { 
    if (k > n) { 
     //impossible 
     return; 
    } 
    //initializing the result set as empty 
    var output = []; 
    //creating a variable 
    var input; 
    //we need k distinct random numbers 
    while (k-- > 0) { 
     //we get a random integer, 0 <= input < n 
     input = Math.floor(Math.random() * n); 
     //if it is duplicated, increment it inside the n'th modulo class until a new value is found 
     while (output.indexOf(input) >= 0) { 
      input = (input + 1) % n; 
     } 
     //store the new distinct value into the results 
     output[output.length] = input; 
    } 
    return output; 
} 

還有很多其他可能的方法。