1.初始化文件
Chrome 官方扩展教程地址
新建一个文件夹 zhi-follow
下图中 1 部分为 默认的图标3种尺寸
会显示在 Chrome 中
 

2. 定义按钮样式
 
页面上会有两个展示按钮,方便随时控制收听的进度
 
 .follow_them_box{
position: fixed;
right: 200px;
top: 200px;
background-color: #fff;
width: 80px;
height: 30px;
line-height: 30px;
text-align: center;
cursor: pointer;
background: #8ab923;
background-color: #9dcc4a;
background-image: linear-gradient(top,#adda4d,#86b846);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#adda4d', endColorstr='#86b846', GradientType=0);
text-shadow: 0 1px 0 rgba(255,255,255,.3);
border: 1px solid #6d8f29;
color: #3e5e00!important;
border-radius: 5px;
box-shadow: 0 1px 0 rgba(255,255,255,.5) inset,0 1px 0 rgba(0,0,0,.2);
}
.remove_box{
top: 260px;
}
3. manifest.json 文件配置
 
JSON做配置文件非常方便 PHP Python等都有便利的第三方包来解析
 
配置文件说明:
 
background 用来配置后台默认运行的JS 这里我们不需要。
content_scripts 用来配置在页面中载入的静态资源 matches来确定我们的资源会被加载到哪些域名
 
其他配置就是一些版本说明等。
 
js 这一栏配置上要加载的jQuery框架和我们的程序js
 
 {
"background": {
"persistent": false,
"scripts": [ "background.js" ]
},
"content_scripts": [ {
"css": [ "show_follow.css" ],
"exclude_matches": [ "http://www.zhihu.com/read" ],
"js": [ "jquery-2.1.1.min.js","show_follow.js"],
"matches": [ "http://www.zhihu.com/*" ]
} ],
"description": "批量收听指定用户的好友",
"icons": {
"128": "128.png",
"16": "16.png",
"48": "48.png"
},
"manifest_version": 2,
"name": "「批量+」",
"permissions": [ "storage" ],
"short_name": "批量+",
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "1.0"
}
4. 写入主要功能
show_follow.js 相当于我们的入口文件,可定义各种功能。
 
4.1 先定义需要插入页面的dom按钮
4.2 绑定按钮事件
4.3 获取知乎页面中的 xsrf 值,否则无法提交表单
4.4 批量关注
 
jQuery(document).ready(function($) {
var z_url = "www.zhihu.com";
var follow = {
uchk_obj : $('.zm-profile-header-info-title'),
flink : $('.zm-profile-side-following>a').attr('href'),
fl_btn_obj : $('.zg-btn-follow'),
fl_them_div : '<div class="follow_them_box" id="follow_them_box" title="本按钮只在用户好友页有效,收听当前所有新人">follow them</div>',
remove_div : '<div class="follow_them_box remove_box" id="remove_box" title="清除页面中已经收听过的人">remove</div>',
hash_array : new Array(),
uchk : function(){
if (follow.uchk_obj.html() == '获得'){
return true;
}else{
console.info('uchk');
return false;
}
},
show_fl_btn : function(){
$('body').append(follow.fl_them_div);
$('body').append(follow.remove_div);
},
follow_user : function(uid,xsrf){
$.ajax({
url: '/node/MemberFollowBaseV2',
data: {method:'follow_member',
params:'{"hash_id":"'+uid+'"}',
_xsrf:xsrf
},
dataType: "text",
type: "POST",
success: function(response) {
}
});
},
//删除已收听过的人
remove_followed : function(){
$('#remove_box').on("click", function(){
var temp = '';
var uid = '' ;
//清空已收听
$('.zg-btn-unfollow').each(function(index, el) {
temp = $(this).html();
switch(temp){
case '取消关注':
$(this).parents('.zm-profile-section-item').css('display', 'none');
break;
default:
break;
}
});
});
},
follow_them : function(){
$('#follow_them_box').on("click", function(){
var xsrf = $("input[name='_xsrf']").val();
$('.zg-btn-follow').each(function(index, el) {
uid = $(this).attr('data-id');
$(this).parents('.zm-profile-section-item').css('display', 'none');
follow.hash_array.push(uid);
});
var times = 0;
var max_num = 0;
if (follow.hash_array.length < 50){
max_num = follow.hash_array.length;
}else{
max_num = 50;
}
var int=self.setInterval(function(){
follow.follow_user(follow.hash_array[times],xsrf);
times++;
if (times == max_num){
follow.hash_array = [];
int=window.clearInterval(int);
}
},1000);
});
}
};
if ( follow.uchk() ){
follow.show_fl_btn();
follow.remove_followed();
follow.follow_them();
}
});
操作演示:
 
1. 在Chrome扩展中载入扩展包
 
 
2. 打开知乎你需要复制关注的页面
 
其中灰色的是已经关注过的,点下 remove 按钮即可去除
 
点击 follow them 可关注 当前页面可以关注的所有人
 
 
 
Chrome HTTP 请求状态
 

收听完毕。

源文件 下载地址: https://github.com/Martin-Tan/zhi-follow

通过Chrome扩展来批量复制知乎好友的更多相关文章

  1. Chrome扩展程序——TabCopy:一键复制网页标题和网址

    Chrome扩展程序——TabCopy:一键复制网页标题和网址 - Erik_ly的博客 - CSDN博客 https://blog.csdn.net/u012318074/article/detai ...

  2. 前端程序员必知的30个Chrome扩展-[转载]

    谷歌Chrome浏览器是网络上可用的最好浏览器之一,并且自2011年11月超越了Firefox浏览器之后,已经成为了互联网上占主导地位的浏览器.今天,HTML5中国与大家分享一些实用的谷歌Chrome ...

  3. 分享一些好用的 Chrome 扩展

    阅读本文大概需要 2.8 分钟. 前言 使用浏览器扩展程序可以使你的工作效率提高数倍不止,那么下面我就向大家分享一下我日常使用的扩展,可能大多数扩展大家都已经在使用了,不过也难免有一两个是你不知道的. ...

  4. Web 开发人员必备的12款 Chrome 扩展程序

    之前已经分享过一些帮助 Web 开发人员和设计师的 Chrome 扩展,这次我们继续展示一组很有用的 Chrome 应用程序.这些免费的 Chrome 应用程序可以简化您的工作流程,为了加快您的工作流 ...

  5. Google Chrome 扩展程序开发

    根据公司的规定,每月八小时,弹性工作制.所以大家平时来的不太准时,如果有事,下班也就早些回去了.所以一个月下来工作时间可能不够,但是公司的考勤日历是这样的: 除了请假和法定节假日外,其他样式显示都是一 ...

  6. 实现chrome扩展启动本地进程 - 补充

    实现chrome扩展启动本地进程 - 补充 标签: chrome扩展启动本地程序访问本地磁盘 2014-10-17 11:42 6753人阅读 评论(17) 收藏 举报  分类: Chrome Plu ...

  7. Chrome扩展开发(Gmail附件管理助手)系列之〇——概述

    目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...

  8. Chrome扩展开发之一——Chrome扩展的文件结构

    目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...

  9. Chrome扩展开发之三——Chrome扩展中的数据本地存储和下载

    目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...

随机推荐

  1. Ajax基础与Json应用(二)

    九.jQuery 实现Ajax应用 1.使用load()方法异步请求数据 使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为: load(url, ...

  2. Android下载文件提示文件不存在。。。 java.io.FileNotFoundException

    遇到这个错误java.io.FileNotFoundException,事实上文件是存在的,把地址复制到手机浏览器都能够直接下载的,但为嘛不能下载呢. Error in downloadBitmap ...

  3. Python 数组[],元组(),字典{}的异同

    序列 Python有6中内建的序列,在这里我们重点讨论两种,数组和元组.所有序列都可以做某些特定的操作,大致上常用的是:加,乘,索引,分片以及检查某个元素是否属于序列的成员. Python还提供一些内 ...

  4. [Redux] Important things in Redux

    Root Smart component can be overloaded, divide 'smart' component wisely & using Provider. Proble ...

  5. 面试无忧之Zookeeper总结心得

    为什么需要分布式系统 l 单机系统已经无法满足业务需要 l 高性能硬件价格昂贵 分布式系统带来哪些问题 l 集群中节点数据一致性问题 l 集群产生分区 l 负载问题 l 幂等性问题 l 可用性问题 l ...

  6. Android 开发者工具

    30多个Android 开发者工具 文中部分工具是收费的,但是绝大多数都是免费的. FlowUp 这是一个帮助你跟踪app整体性能的工具,深入分析关键的性能数据如FPS, 内存, CPU, 磁盘, 等 ...

  7. 小强的HTML5移动开发之路(22)—— Adobe DreamWeaver CS6安装与破解

    首先说明一下,这里介绍Adobe DreamWeaver CS6的安装与破解是为了后面的jQuery Mobile框架使用做好准备. 一.首先去Adobe官网下载:http://www.adobe.c ...

  8. 【9210】找礼物(char* num[2000]的使用 get char num[i] = new char[1000])

    Time Limit: 10 second Memory Limit: 2 MB 问题描述 新年到了,突然间,就在那美丽的一霎那,你好友和你(K个人)的周围满是礼物,你发扬你帅气的风格,让你的好友先拿 ...

  9. 关于Dagger 2的文章汇总

    首先是我真正看懂了的第一篇文章 代码GG之家的 Dagger2图文详解 这篇文章很直接,还配有代码demo.至少我是看懂了. Dagger2 使用详解 这篇文章同样配有demo,同时文末还有很多有用的 ...

  10. htmlunit 模拟登录 无验证码

    1.模拟登录csdn,最开始的时候使用的是httpclient,网上的所有模拟登录csdn的版本都是找到lt/execution/event_id.连同用户名及密码 一起发送即可,但是目前的csdn的 ...