arm*_*rma 6 javascript jquery userscripts
我想问一下是否可以构建Chrome或Greasemonkey脚本,可以打开队列中的所有弹出窗口.到目前为止,我有两个单独的脚本,但由于弹出窗口具有反垃圾邮件功能,同时不允许太多的脚本,因此效果不佳.
我想要做的是以队列方式处理弹出链接数组,并仅在前一个关闭时打开.当它归结为队列和任何类型的事件绑定时,我没有任何经验.
所以我得到的资源:
1)已准备好的链接数组
var URL_Array = [];
$('form[name="form_gallery"] .img img').each(function(i,e){
// Format URL array here
if($(this).closest('.object').children('.phs_voted_count').length == 0){
var string = e.src;
var nowBrake = string.substring(string.length-7,7);
var splited = nowBrake.split('/');
var urlStr = '/window/friend/gallery_view/'+splited[3]+'/'+splited[4]+'.html';
URL_Array[i] = urlStr;
}
});
Run Code Online (Sandbox Code Playgroud)
2)在弹出窗口中对图像进行投票的脚本
/*######################################################*/
var voteBy = '#vte_mark_12'; // Prefered vote icon
var voteDefault = '#vte_mark_5'; // Default vote icon
var voteFormLoc = 'image_voting'; // Image voting popups form
var buyExtraVote = 'image_voting_buy'; // If run out of votes buy more
var captchaLoc = 'input[name="captcha"]'; // Captcha input field
var captchaTxt = 'Enter captcha text!'; // Captcha alert text
var simpatyFormId = '#sym_send'; // Simpaty window form
var startScript = true;
var formProcessedAlready = false; // Used to check if image already was voted
/*######################################################*/
$(function(){
if(startScript){
if($(captchaLoc).length > 0){
alert(captchaTxt);
$(captchaLoc).focus().css('border', '2px solid red');
return false;
}else{
if($('#50').length > 0){
$('#50').attr('checked', true);
$('form').attr('id', buyExtraVote);
$('#'+buyExtraVote).submit();
}else{
$('form').attr('id', voteFormLoc);
if($(voteBy).length > 0){
$(voteBy).attr('checked', true);
setTimeout("$('#"+voteFormLoc+"').submit()", 2000);
}else if($(voteDefault).length > 0){
$(voteDefault).attr('checked', true);
setTimeout("$('#"+voteFormLoc+"').submit()", 2000);
}else{
// If we have simpaty box autocast submit
if($(simpatyFormId).length > 0){
if($(captchaLoc).length > 0){
alert(captchaTxt);
$(captchaLoc).focus().css('border', '2px solid red');
return false;
}else{
$(simpatyFormId).submit();
formProcessedAlready = true;
}
}else{
formProcessedAlready = true;
}
}
}
}
if(formProcessedAlready){
self.close();
}
}
});
Run Code Online (Sandbox Code Playgroud)
据我所知,它应该是这样的:
1)获取所有未投票的网址和表格数组(完成)
2)将所有弹出窗口排队打开
3)开始第一次弹出窗口
4)投票完成并弹出窗口关闭(完成)
5)开始第二次弹出
6)当数组完成切换到下一页(完成)
你认为呢?
确切的 URL 很重要,因为脚本需要处理主页和弹出窗口,并且对每个页面进行不同的操作。
\n\n有两种主要方法来处理这个问题。任何一个:
\n\n使用include指令确保脚本在主页和弹出窗口上运行,但根据页面类型切换其行为。这将使脚本的两个不同实例同时运行,这不是问题。
使用include和 可能的exclude指令来确保脚本仅在主页上运行。然后让弹出窗口打开代码操作表单。
以下是方法 1 的操作方法:
\n\n(1) 假设主页面如下:
\n\xc2\xa0 \xc2\xa0 somewhere.com/main/*
\n \xc2\xa0 \xc2\xa0 ,弹出页面如下:
\n \xc2\xa0 \xc2\xa0 somewhere.com/window/friend/gallery_view/*
\n \ xc2\xa0 \xc2\xa0 确保脚本的包含指令在两组页面上均触发。
(2) 确保 jQuery 在两种页面上都可用。推荐使用 jQuery 1.5.1。jQuery 1.3.2 可能不适用于以下代码。
\n\n(3) 然后像下面这样的代码应该可以工作:
\n\nvar URL_Array = [];\nvar PopupQueue = $({}); //-- jQuery on an empty object - a perfect queue holder\n\n//--- Is this a popup window or the main page?\n\nif ( /\\/window\\/friend\\/gallery_view\\//i.test (window.location.href) )\n{\n //--- This is a popup page\n\n /*######################################################*/ \n var voteBy = \'#vte_mark_12\'; // Prefered vote icon\n var voteDefault = \'#vte_mark_5\'; // Default vote icon\n var voteFormLoc = \'image_voting\'; // Image voting popups form\n var buyExtraVote = \'image_voting_buy\'; // If run out of votes buy more\n var captchaLoc = \'input[name="captcha"]\'; // Captcha input field\n var captchaTxt = \'Enter captcha text!\'; // Captcha alert text\n var simpatyFormId = \'#sym_send\'; // Simpaty window form\n\n var startScript = true; \n var formProcessedAlready = false; // Used to check if image already was voted\n /*######################################################*/ \n\n $(function(){\n if(startScript){\n if($(captchaLoc).length > 0){\n alert(captchaTxt);\n $(captchaLoc).focus().css(\'border\', \'2px solid red\');\n return false;\n }else{\n if($(\'#50\').length > 0){\n $(\'#50\').attr(\'checked\', true);\n $(\'form\').attr(\'id\', buyExtraVote);\n $(\'#\'+buyExtraVote).submit();\n }else{\n $(\'form\').attr(\'id\', voteFormLoc);\n if($(voteBy).length > 0){\n $(voteBy).attr(\'checked\', true);\n setTimeout("$(\'#"+voteFormLoc+"\').submit()", 2000);\n }else if($(voteDefault).length > 0){\n $(voteDefault).attr(\'checked\', true);\n setTimeout("$(\'#"+voteFormLoc+"\').submit()", 2000);\n }else{\n // If we have simpaty box autocast submit\n if($(simpatyFormId).length > 0){\n if($(captchaLoc).length > 0){\n alert(captchaTxt);\n $(captchaLoc).focus().css(\'border\', \'2px solid red\');\n return false;\n }else{\n $(simpatyFormId).submit();\n formProcessedAlready = true;\n }\n }else{\n formProcessedAlready = true;\n }\n }\n }\n }\n\n if(formProcessedAlready){\n self.close();\n }\n }\n });\n}\nelse\n{ //--- This is a main page\n\n $(\'form[name="form_gallery"] .img img\').each(function(i,e){\n // Format URL array here\n if($(this).closest(\'.object\').children(\'.phs_voted_count\').length == 0){\n var string = e.src;\n var nowBrake = string.substring(string.length-7,7);\n var splited = nowBrake.split(\'/\');\n var urlStr = \'/window/friend/gallery_view/\'+splited[3]+\'/\'+splited[4]+\'.html\';\n URL_Array[i] = urlStr;\n }\n });\n\n //--- Load up the queue.\n $.each (URL_Array, function (PopupNum, PopupURL) {\n\n PopupQueue.queue (\'Popups\', function (NextQ_Item) {\n\n OpenPopupFromQueue (NextQ_Item, PopupNum+1, PopupURL);\n } );\n } );\n\n //--- Launch the Popups, one at a time.\n PopupQueue.dequeue (\'Popups\');\n}\n\n\nfunction OpenPopupFromQueue (NextQ_Item, PopupNum, PopupURL)\n{\n var PopupWin = window.open (PopupURL, "_blank");\n if (!PopupWin)\n {\n console.log (\'Bad URL \' + PopupURL)\n setTimeout (function() { NextQ_Item (); }, 2003);\n return;\n }\n\n /*--- Only after the popup has loaded can we do any processing.\n */\n PopupWin.addEventListener (\n "load",\n function () {\n /*--- Setup the listener for when the popup has closed.\n We fire the next popup from the queue, there.\n */\n PopupWin.addEventListener (\n "unload",\n function () {\n PopupClosed (NextQ_Item);\n },\n false\n );\n\n /*--- We could process the popup here, but it\'s better to let another instance of this\n script do it, instead.\n */\n },\n false\n );\n}\n\n\nfunction PopupClosed (NextQ_Item)\n{\n //--- Launch the next popup from the queue.\n NextQ_Item ();\n}\nRun Code Online (Sandbox Code Playgroud)\n