适用于 2 页的书签

2024-02-03

I'm using a bookmarklet to inject javascript into a webpage. I am trying to login into my gmail account(that part works) and in my gmail account automatically click Sent folder as the page loads. This is the starting page: enter image description here

这是我在书签中使用的代码:

javascript:
document.getElementById('Email').value='[email protected] /cdn-cgi/l/email-protection';
document.getElementById('next').click();
setTimeout(function(){
document.getElementById('Passwd').value='myPassword';
document.getElementById('signIn').click();},1000);

setTimeout(function(){
document.getElementsByClassName("J-Ke n0 aBU")[0].click();
},6000);

J-Ke n0 aBU是类别Sent文件夹。此代码登录到我的帐户,但没有单击“已发送”文件夹。

我在其他网站上注意到类似的行为;每当加载或刷新新页面时,小书签就会停止工作。
这是为什么?在与最初单击的页面不同的页面上使用相同书签的正确方法是什么。


免责声明:我没有 gmail,所以我没有专门针对 gmail 进行测试。
这个答案的存在是为了解决你的评论 https://stackoverflow.com/questions/33481824/bookmarklet-that-works-on-2-pages#comment54753376_33482566:

iframe 怎么样?理论上是否可以在 iframe 中使用 gmail 登录,因此当 iframe 更改到另一个页面时,这不会对书签产生影响?

是的,技术上可以有一个持久的小书签使用 iframe(或者,上帝保佑,框架集)。
只要您的父窗口(并且它包含 iframe)保留在相同的域,它应该根据跨域规范工作。
然而,有可能(取决于所使用的方法)(非)有意地“反作用”(根据所使用的反作用,仍然可以被规避,等等)。

导航到网站,然后执行书签:

  • 创建 iframe。
  • 将 onload-handler 设置为 iframe。
  • 用 iframe 替换当前网页内容(到窗口的完整宽度和高度)。
  • 将 iframe 的源设置为当前 url(在注入的 iframe 中重新加载当前打开的页面)。

然后 iframe 的 onload-handler 的工作是检测(使用 url/title/page-content)加载了哪个页面以及应该采取哪些(如果有)操作。

示例(缩小(去除注释和不需要的空格)使用Dean Edward 的 Packer v3 http://dean.edwards.name/packer/):

javascript:(function(P){
  var D=document
  ,   B=D.createElement('body')
  ,   F=D.createElement('iframe')
  ; //end vars
  F.onload=function(){
    var w=this.contentWindow     //frame window
    ,   d=w.document             //frame window document
    ; //end vars
    //BONUS: update address-bar and title. 
    //Use location.href instead of document.URL to include hash in FF, see https://stackoverflow.com/questions/1034621/get-current-url-in-web-browser
    history.replaceState({}, D.title=d.title, w.location.href ); 
    P(w, d);        //execute handler
  };
  D.body.parentNode.replaceChild(B, D.body);   //replace body with empty body
  B.parentNode.style.cssText= B.style.cssText= (
   F.style.cssText= 'width:100%;height:100%;margin:0;padding:0;border:0;'
  ) + 'overflow:hidden;' ;           //set styles for html, body and iframe
  //B.appendChild(F).src=D.URL; //doesn't work in FF if parent url === iframe url
  //B.appendChild(F).setAttribute('src', D.URL); //doesn't work in FF if parent url === iframe url
  B.appendChild(F).contentWindow.location.replace(D.URL); //works in FF
}(function(W, D){   //payload function. W=frame window, D=frame window document
  alert('loaded');
  // perform tests on D.title, W.location.href, page content, etc.
  //   and perform tasks accordingly
}));

注意:进一步缩小的明显方法之一是对 createElement、contentWindow 等使用带有字符串变量的括号访问。

这是要使用的有效负载函数(来自上面的小书签)的示例函数体http://www.w3schools.com http://www.w3schools.com/(抱歉,我无法很快想到另一个目标):

var tmp;
if(D.title==='W3Schools Online Web Tutorials'){
  //scroll colorpicker into view and click it after 1 sec
  tmp=D.getElementById('main').getElementsByTagName('img')[0].parentNode;
  tmp.focus();
  tmp.scrollIntoView();
  W.setTimeout(function(){tmp.click()},1000);
  return;
}
if(D.title==='HTML Color Picker'){
  //type color in input and click update color button 'ok'
  tmp=D.getElementById('entercolorDIV');
  tmp.scrollIntoView();
  tmp.querySelector('input').value='yellow';
  tmp.querySelector('button').click();

  //click 5 colors with 3 sec interval
  tmp=D.getElementsByTagName('area');
  tmp[0].parentNode.parentNode.scrollIntoView();
  W.setTimeout(function(){tmp[120].click()},3000);
  W.setTimeout(function(){tmp[48].click()},6000);
  W.setTimeout(function(){tmp[92].click()},9000);
  W.setTimeout(function(){tmp[31].click()},12000);
  W.setTimeout(function(){tmp[126].click()},15000);
  return;
}

上面的示例(在小书签内)已缩小:

javascript:(function(P){var D=document,B=D.createElement('body'),F=D.createElement('iframe');F.onload=function(){var w=this.contentWindow,d=w.document;history.replaceState({},D.title=d.title,w.location.href);P(w,d)};D.body.parentNode.replaceChild(B,D.body);B.parentNode.style.cssText=B.style.cssText=(F.style.cssText='width:100%;height:100%;margin:0;padding:0;border:0;')+'overflow:hidden;';B.appendChild(F).contentWindow.location.replace(D.URL)}(function(W,D){var tmp;if(D.title==='W3Schools Online Web Tutorials'){tmp=D.getElementById('main').getElementsByTagName('img')[0].parentNode;tmp.focus();tmp.scrollIntoView();W.setTimeout(function(){tmp.click()},1000);return}if(D.title==='HTML Color Picker'){tmp=D.getElementById('entercolorDIV');tmp.scrollIntoView();tmp.querySelector('input').value='yellow';tmp.querySelector('button').click();tmp=D.getElementsByTagName('area');tmp[0].parentNode.parentNode.scrollIntoView();W.setTimeout(function(){tmp[120].click()},3000);W.setTimeout(function(){tmp[48].click()},6000);W.setTimeout(function(){tmp[92].click()},9000);W.setTimeout(function(){tmp[31].click()},12000);W.setTimeout(function(){tmp[126].click()},15000);return}}));

希望这对您有所帮助(您开始了)!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

适用于 2 页的书签 的相关文章

随机推荐

  • 使用 laravel 和 vuejs 导出 Excel

    我喜欢使用 Laravel 和 Vuejs 导出 Excel 不知何故 代码返回真实值 但无法下载 Excel 文件 如果我执行正常请求 它将下载文件 但在 axios 请求中 它不会导出文件 我正在使用 php artisan make
  • 复制另一个账户拥有的 AMI 时出现问题

    我正在尝试从一个账户 A 复制一个由另一个账户 B 拥有的 AMI 我之前已经构建过此 AMI 帐户 A 具有 AMI 的启动权限 但当我复制时 收到以下错误消息 Images from AWS Marketplace cannot be
  • 在 R 中使用 foreach 读取全局变量

    我正在尝试使用 RStudio 在具有 16 核 CPU 和 64 GB RAM 的 Windows 服务器上运行 foreach 循环 使用 doParallel 包 工作 进程从 for 循环外部复制所有变量 通过运行 foreach
  • 如何生成包含 JSON 结构的下载文件?

    我的控制器中有这个方法 public IActionResult Download return Json context Users 我注意到它生成了正确的 JSON 结构but它在浏览器中呈现为普通文本 我希望将其下载到客户的计算机上
  • 输出模板内的嵌套类

    我试图重载 ostream 运算符以允许输出模板内的嵌套类 但是 编译器无法将实际的函数调用绑定到我的重载 template
  • iOS:(Swift)如何显示距当前位置的距离并在注释副标题上存在注释

    我目前正在使用 Swift 语言开发基于 iOS 的地图应用程序 我想要一个建议 因为在我在地图视图上绘制所有引脚之后 我使用名为 Alamofire 的 JSON 框架从服务器接收数据 我希望地图上所有注释的副标题显示距用户当前位置的距离
  • Fabricjs,旋转对象后是否可以获得虚拟矩形的左、上、右位置

    旋转物体后是否可以获得虚拟矩形的左 上 右位置 您正在寻找的是边界矩形你的对象 获取边界矩形 忽略Vpt Object 返回对象边界矩形的坐标 左 上 宽 高 该框旨在与画布轴对齐 返回 具有 left top width height 属
  • 在源代码中保护密码?

    我的代码中有一个密码 需要连接到 sftp 服务器 混淆 或隐藏在代码中的最佳方法是什么 Thanks 不要将密码存储在源代码中 而是将其存储在 App Config 或 Web Config 内的受保护部分中 See 使用受保护的配置加密
  • C++ 在模板类中重载运算符<< [重复]

    这个问题在这里已经有答案了 可能的重复 为模板类重载友元运算符 https stackoverflow com questions 4660123 overloading friend operator for template class
  • 回历日期格式

    我有一些从网站下载的数据 其中一列包含回历日期 为了使该列成为正确的日期列 我应用了以下格式 但问题是 除非我输入单元格 通过双击或 F2 然后按 Enter 键 否则它不会被视为日期并向右对齐 因为行数很大 所以我使用的方法不实用 我尝试
  • php 中 HTTPRequest 的替代方案

    我在 php 脚本中使用 HttpRequest 类 但是当我将此脚本上传到托管提供商的服务器时 执行它时出现致命错误 致命错误 在第 87 行 中找不到类 HttpRequest 我相信原因是因为我的托管提供商的 php ini 配置不包
  • android模拟器的IP地址是多少,[重复]

    这个问题在这里已经有答案了 android模拟器的IP地址是多少 根据我在互联网上找到的几个信息 127 0 0 1 10 0 0 2或10 0 015从Web服务器 apache 调用模拟器 模拟器的端口是固定的吗 10 0 2 1 路由
  • 如何正确广播 NumPy 数组的数组索引

    简短的介绍 我有两个 numpy 数组 data data shape是一个包含 X 个条目的元组 indices indices shape是元组 X Y indices基本上是一个索引数组的列表 沿第二个维度的数组指定相应维度的索引列表
  • 在新 API 的两个单独文件中初始化 Firebase 引用

    我已升级到新的 API 但不知道如何在两个单独的文件中初始化 Firebase 引用 CASE 1 1st file var config firebase initializeApp config var rootRef firebase
  • ArrayList初始化相当于数组初始化[重复]

    这个问题在这里已经有答案了 我知道您可以在实例化期间初始化数组 如下所示 String names new String Ryan Julie Bob 有没有办法用 ArrayList 做同样的事情 或者我必须单独添加内容array add
  • 以编程方式运行 Ansible playbook?

    我有一个 python 应用程序 它调用下面的代码 并计划通过 Ansible API 以编程方式运行 Ansible playbook 而不是使用子进程之类的东西 下面的代码运行但实际上似乎没有执行任何内容 获取结果的输出只会给我一个看起
  • 如何在 bash 脚本中自动按 [ENTER] 继续

    我有一个 bash 脚本 可以帮助自动安装一些应用程序 One app requests that I press ENTER to continue or CTRL C to cancel How can I automate my sc
  • 风暴集群重复元组

    目前我正在开展一个项目 在该项目中我在四台 Unix 主机上设置了一个 Storm 集群 拓扑本身如下 JMS Spout 侦听 MQ 以获取新消息 JMS Spout 解析然后将结果发送到 Esper Bolt 然后 Esper Bolt
  • 引导程序中的字形不显示

    div class container fluid div class sidebar left div class well h5 Administration h5 ul class administration list li cla
  • 适用于 2 页的书签

    I m using a bookmarklet to inject javascript into a webpage I am trying to login into my gmail account that part works a