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. Visual Studio Debugger

    Visual Studio Debugger中七个鲜为人知的小功能   Visual Studio debugger是一个很棒的调试工具,可以帮助程序猿们快速地发现和解决问题.这里给大家简单介绍一下V ...

  2. Android 实现Xmpp工具类

    /** * XMPP服务器连接工具类. * * @author chen.lin * */ public class XmppManager { private static final String ...

  3. AnimatorSet和PropertyValuesHolders.ofKeyframe

    如果要多个动画配合工作,需要把他们放入AnimatorSet中 ObjectAnimator animator1 = ObjectAnimator.ofFloat(...); animator1.se ...

  4. 经典卷积神经网络的学习(三)—— Inception Net

    Google Inception Net 首次出现在 ILSVRC 2014 的比赛中(和 VGGNet 同年),就以较大优势拔得头筹.那届比赛中的 Inception Net 一般被称为 Incep ...

  5. effective c++ 条款7

    1.随着多态基类应该声明一个质virtual析构函数. 假定class由于不管是什么virtual析构函数, 它应该有一个virtual析构函数. 2.classed的设计目的假设不是作为base c ...

  6. C# 直接创建多个类和使用反射创建类的性能

    原文:C# 直接创建多个类和使用反射创建类的性能 本文告诉大家我对比的使用直接创建多个类和使用反射创建多个类的性能 在上一篇 C# 程序内的类数量对程序启动的影响 的基础上,继续做实验 现在创建 10 ...

  7. 《node.js开发指南》第五章与新版Node变化太大的一些问题

    1.在win下,命令行工具express -h无效,因为4.x版本的express需要安装express-generator才可以使用express命令,npm install -g express- ...

  8. jquer表单序列化加强版

    相同name值会转化为一个数组 $.fn.serializeObject = function(){ var o = {}; var a = this.serializeArray(); $.each ...

  9. PFIF网上寻人协议

    原文:http://www.csdn.net/article/2013-04-22/2814980 本文的主要内容来自Wikipedia(http://en.wikipedia.org/wiki/Pe ...

  10. 安装mysql5.7.17

    参见 网易云课堂的视频教程 :mysql视频教程