2019独角兽企业重金招聘Python工程师标准>>>

源文件:

  • contentscript.js
  • manifest.json

manifast.json代码:

{"name": "Content Script Cross-Domain XMLHttpRequest Example","version": "2.0.0","description": "Demonstrates making cross domain requests from a content script by putting Twitter trends on Google News.","permissions": ["https://api.twitter.com/*"],"icons": {"48" : "sample-48.png","128" : "sample-128.png"},"content_scripts": [{"matches": ["http://news.google.com/*"],"js" : ["contentscript.js"]}]
}

contentscript.js代码:

/*
* Copyright (c) 2011 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*//*** Performs an XMLHttpRequest to Twitter's API to get trending topics.** @param callback Function If the response from fetching url has a*     HTTP status of 200, this function is called with a JSON decoded*     response.  Otherwise, this function is called with null.*/
function fetchTwitterFeed(callback) {var xhr = new XMLHttpRequest();xhr.onreadystatechange = function(data) {if (xhr.readyState == 4) {if (xhr.status == 200) {var data = JSON.parse(xhr.responseText);callback(data);} else {callback(null);}}}// Note that any URL fetched here must be matched by a permission in// the manifest.json file!var url = 'https://api.twitter.com/1/trends/daily.json?exclude=hashtags';xhr.open('GET', url, true);xhr.send();
};/*** Parses text from Twitter's API and generates a bar with trending topics at* the top of the current page** @param data Object JSON decoded response.  Null if the request failed.*/
function onText(data) {// Only render the bar if the data is parsed into a format we recognize.if (data.trends) {// Create the overlay at the top of the page and fill it with data.var trends_dom = document.createElement('div');var title_dom = document.createElement('strong');title_dom.innerText = 'Topics currently trending on Twitter:';trends_dom.appendChild(title_dom);for (var key in data.trends) {for (var i=0,trend; trend = data.trends[key][i]; i++) {var link_dom = document.createElement('a');link_dom.setAttribute('href', trend.url)link_dom.innerText = trend.name;link_dom.style.color = '#000';trends_dom.appendChild(document.createTextNode(' '));trends_dom.appendChild(link_dom);}break;}trends_dom.style.cssText = ['background-color: #ffd700;','background-image: -webkit-repeating-linear-gradient(' +'45deg, transparent, transparent 35px,' +'rgba(0,0,0,.1) 35px, rgba(0,0,0,.1) 70px);','color: #000;','padding: 10px;','font: 14px Arial;'].join(' ');document.body.style.cssText = 'position: relative';document.body.parentElement.insertBefore(trends_dom, document.body);}
};fetchTwitterFeed(onText);

转载于:https://my.oschina.net/u/867090/blog/142092

chrome插件,脚本中实现跨域请求相关推荐

  1. HTTP中CORS跨域请求的实现(C++|Qt框架实现)

    目录 背景 关键 演示及源码 背景 HTTP中CORS跨域请求,可以获取其他服务器的数据: 这里用Qt框架实现! 逻辑如下: 浏览器访问127.0.0.1:80端口!80端口请求了127.0.0.1: ...

  2. HTTP中的跨域请求、HTTP报文结构、状态码

    目录 一.前驱知识学习 (1)请求报文 (2)响应报文 二.HTTP中的跨域请求 1. 什么是跨域请求 2.什么是同源策略 3.为什么要设置这种限制 3.1 攻击实例 3.2 攻击原理 4. 怎样取消 ...

  3. axios请求跨域前端解决_Vue中axios跨域请求解决方法

    跨域:指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对JavaScript施加的安全限制. 所谓同源是指,域名,协议,端口均相同,浏览器执行 js 脚本时,会检查这个脚本属 ...

  4. react中 ajax跨域请求

    因为项目需要,目前需要通过react ajax请求,实现请求其它域的登录URL,将用户写入到其它域的cookie中,之后herf连接该网址的其他内容的时候,便可直接跳转到对应内容,无需跳转到登录页面. ...

  5. java中ajax跨域请求

    最近在项目中要使用到跨域请求验证码然后再提交的问题.由于验证码是存在session里的,而跨域请求在后台获得的session每次都不一样,导致验证码无法比对.网上查找的方法都比较含糊,最后解决了决定写 ...

  6. [油猴脚本开发指南]脚本ajax的跨域请求

    转载自油猴中文网:bbs.tampermonkey.net.cn 李恒道QQ4548212 油猴中文网bbs.tampermonkey.net.cn TamperMonkey GreaseMonkey ...

  7. jQuery中ajax跨域请求

    背景介绍: 现在做的课题要实现在一个没有部署在服务器上的网页中,使用ajax来加载已经 部署在服务器上的一个服务提供的数据. 先看静态页面的代码: <html><head>&l ...

  8. chrome本地文件加载跨域请求

    mac下执行:open -a Google\ Chrome --args -disable-web-security 转载于:https://www.cnblogs.com/Gukw/archive/ ...

  9. Java中SSM框架解决跨域请求

    方法一:@CrossOrigin注解的方法,只能作用在一个Controller层 直接在Controller类或方法前加上@CrossOrigin注解即可允许所有ip跨域访问 加在Controller ...

  10. 用springmvc 开发为 app 提供后台服务遇到跨域请求的问题

    浏览器使用的chrome,安装了cors插件(开启允许跨域请求) 然后访问远程服务器提供的服务的时候,浏览器console 输出如下形式的错误信息: 问题1.OPTION: xxxxxx url地址 ...

最新文章

  1. #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】
  2. Docker安装Hadoop
  3. PPC 调用约定 r0-r31寄存器介绍
  4. ABAP Modification browser SE95
  5. Class的getResource与ClassLoader的getResource路径/问题
  6. python manager与basemanager_使用Python多处理管理器(BaseManager/SyncManager)与远程计算机共享队列时出现管道中断...
  7. leetcode186. 翻转字符串里的单词 II
  8. java dijkstra算法代码_[转载]Java实现dijkstra算法: 地图中任意起点寻找最佳路径...
  9. kindeditor 4 指定生成文件的时间日期/动态获取My97的时间
  10. linux打开anaconda的jupyter_Linux Centos7安装anaconda3和jupyter
  11. Logstash + DataHub + MaxCompute/StreamCompute 进行实时数据分析
  12. YOLOX目标检测模型Keras实现,超越Yolov5
  13. 自学python买什么教材-最好的Python入门教材是哪本?
  14. oracle存储过程中返回一个程序集
  15. 经典商业融资计划书PPT模板
  16. VMware安装VMwareTolls
  17. Loaders 的使用,结合Fragments
  18. 汽配行业最适合的ERP系统
  19. .ServletException: Circular view path [index]: would dispatch back to the curren这是springboot
  20. LeetCode 零矩阵

热门文章

  1. MATLAB的sum函数
  2. 支持各硬件平台的机器学习模型 AWS发表新开源项目
  3. MFC选择目录和多个文件
  4. Hbase与传统关系型数据库对比
  5. 在Django中使用F()函数
  6. Hibernate实体类注解中如何忽略某些字段的映射
  7. jQuery中的100个技巧
  8. 我和linux的第十三天
  9. Linux操作系统基本使用知识
  10. 系统开机 linux 时间不对,linux下查看系统运行时间和最近一次的开机启动时间