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. 王立平--TableLayout

    效果: <?xml version="1.0" encoding="utf-8"?>  <TableLayout xmlns:android= ...

  2. OC常用数据类型大全解

    UI基础 OC常用数据类型 Block Block封装了一段代码,可以在任何时候执行 Block可以作为函数参数或者函数的返回值,而其本身又可以带输入参数或返回值.它和传统的函数指针很类似,但是有区别 ...

  3. 孔雀翎----《Programming C# 》中国版 文章4版

    孔雀翎----<Programming C# >中国版 文章4版 页:http://blog.csdn.net/21aspnet/           时间:2007.8.7 电子工业出版 ...

  4. 已解决!Fatal error compiling: 无效的标记(maven启动失败)

    问题描述 Fatal error compiling: 无效的标记 maven启动错误..版本号不对 <plugin> <artifactId>maven-compiler-p ...

  5. 【26.09%】【codeforces 579C】A Problem about Polyline

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. dotnet core 使用 sqlite 部署到 Centos 服务器

    原文:dotnet core 使用 sqlite 部署到 Centos 服务器 本文告诉大家如何创建一个 asp dotnet core 程序,这个程序使用 sqlite 保存,部署程序到 Cento ...

  7. Cordova之打包签名apk

    首先是关于apk签名,Android程序的安装是以包名(package name)进行区分的,就是同样的包名会被认作是同一个程序.这样就可以进行升级.替换.但是包名是一个可以被查看的字符串,这样就可能 ...

  8. Material Design: NavigationView FlaotingActionBar SnackBar采用

    转载 请明确说明 MingsangAndroid 本文介绍了Design Support Library的引入 拥抱Android Design Support Library新变化(导航视图.悬浮A ...

  9. GammaRay is a tool to poke around in a Qt-application(确实很多功能)

    GammaRay is a tool to poke around in a Qt-application and also to manipulate the application to some ...

  10. Disk array controller and information processing apparatus

    A disk array controller has a function of relocating a plurality of data blocks stored in a disk arr ...