gpt4 book ai didi

javascript - 带有弹出窗口的 Chrome 用户脚本中的 jQuery 队列?

转载 作者:数据小太阳 更新时间:2023-10-29 05:27:27 32 4
gpt4 key购买 nike

我想问一下是否可以构建 Chrome 或 Greasemonkey 脚本女巫可以打开队列中的所有弹出窗口。到目前为止,我有 2 个单独的脚本,但效果不佳,因为弹出窗口具有反垃圾邮件功能,不允许同时出现太多脚本。

我想做的是以队列方式处理弹出链接数组,并且仅在上一个关闭时打开下一个。当涉及到队列和任何类型的事件绑定(bind)时,我没有任何经验。

所以我得到的资源:

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;
}
});

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();
}
}
});

据我所知,它应该是这样的:
1) 获取所有未投票的 url 并形成数组(完成)
2) 将所有弹出窗口排队打开
3) 启动第一个弹出窗口
4) 投票完成并关闭弹窗(完成)
5) 开始第二个弹窗
6) 当数组完成后切换到下一页(完成)

你怎么看?

最佳答案

  • 主页和弹出窗口的确切 URL 是什么?
  • 您使用的是什么版本的 jQuery,您是如何使用它的?

确切的 URL 很重要,因为脚本需要同时处理主页和弹出窗口,并且对每个页面进行不同的操作。

他们有 2 种主要方法来处理这个问题。要么:

  1. 使用 include 指令确保脚本在主页和弹出窗口上运行,但根据页面类型切换其行为。这将同时运行两个不同的脚本实例,这不是问题。

  2. 使用include 和可能的exclude 指令来确保脚本 在主页上运行。然后让弹出窗口代码操作表单。


方法 1 的操作方法如下:

(1) 假设主要页面是这样的:
somewhere.com/main/*
弹出页面如下:
somewhere.com/window/friend/gallery_view/*
确保脚本的 include-directives 在两组页面上都触发。

(2) 确保jQuery 在这两种页面上都可用。建议使用 jQuery 1.5.1。 jQuery 1.3.2 可能不适用于以下代码。

(3) 然后像下面这样的代码应该可以工作:

var URL_Array   = [];
var PopupQueue = $({}); //-- jQuery on an empty object - a perfect queue holder

//--- Is this a popup window or the main page?

if ( /\/window\/friend\/gallery_view\//i.test (window.location.href) )
{
//--- This is a popup page

/*######################################################*/
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();
}
}
});
}
else
{ //--- This is a main page

$('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;
}
});

//--- Load up the queue.
$.each (URL_Array, function (PopupNum, PopupURL) {

PopupQueue.queue ('Popups', function (NextQ_Item) {

OpenPopupFromQueue (NextQ_Item, PopupNum+1, PopupURL);
} );
} );

//--- Launch the Popups, one at a time.
PopupQueue.dequeue ('Popups');
}


function OpenPopupFromQueue (NextQ_Item, PopupNum, PopupURL)
{
var PopupWin = window.open (PopupURL, "_blank");
if (!PopupWin)
{
console.log ('Bad URL ' + PopupURL)
setTimeout (function() { NextQ_Item (); }, 2003);
return;
}

/*--- Only after the popup has loaded can we do any processing.
*/
PopupWin.addEventListener (
"load",
function () {
/*--- Setup the listener for when the popup has closed.
We fire the next popup from the queue, there.
*/
PopupWin.addEventListener (
"unload",
function () {
PopupClosed (NextQ_Item);
},
false
);

/*--- We could process the popup here, but it's better to let another instance of this
script do it, instead.
*/
},
false
);
}


function PopupClosed (NextQ_Item)
{
//--- Launch the next popup from the queue.
NextQ_Item ();
}

关于javascript - 带有弹出窗口的 Chrome 用户脚本中的 jQuery 队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5768367/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com