Use Chrome extension to copy friends in batches, and chrome extension friends

Source: Internet
Author: User

Use Chrome extension to copy friends in batches, and chrome extension friends
1.Initialize FileIn the official Chrome extension tutorial address, create a folder named zhi-follow. The first part is the default icon. The three sizes are displayed in Chrome.2. Define button stylesThere are two display buttons on the page to control the listening progress at any time.

 1 .follow_them_box{ 2   position: fixed; 3   right: 200px; 4   top: 200px; 5   background-color: #fff; 6   width: 80px; 7   height: 30px; 8   line-height: 30px; 9   text-align: center;10   cursor: pointer;11   background: #8ab923;12   background-color: #9dcc4a;13   background-image: linear-gradient(top,#adda4d,#86b846);14   background-repeat: repeat-x;15   filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#adda4d', endColorstr='#86b846', GradientType=0);16   text-shadow: 0 1px 0 rgba(255,255,255,.3);17   border: 1px solid #6d8f29;18   color: #3e5e00!important;19   border-radius: 5px;20   box-shadow: 0 1px 0 rgba(255,255,255,.5) inset,0 1px 0 rgba(0,0,0,.2);21 }22 .remove_box{23   top: 260px;24 }
3. manifest. json file configuration  JSON configuration files are very convenient for PHP Python and other third-party packages to parse.Configuration File Description: background is used to configure the default JS running in the background, which is not required here. Content_scripts is used to configure the static resource matches loaded on the page to determine which domain names our resources will be loaded. Other configurations are some version descriptions. The jQuery framework to be loaded and our program js are configured in the js column.
1 {2 "background": {3 "persistent": false, 4 "scripts": ["background. js "] 5}, 6" content_scripts ": [{7" css ": [" show_follow.css "], 8" exclude_matches ": [" http://www.zhihu.com/read "], 9" js ": ["jquery-2.1.1.min.js", "show_follow.js"], 10 "matches": ["http://www.zhihu.com/*"] 11}], 12 "description": "batch listen to friends of a specified user ", 13 "icons": {14 "128": "128.png", 15" 16 ":" 16.png", 16 "48": "48.png" 17}, 18" manifest_version ": 2, 19 "name": "" batch + ", 20" permissions ": [" storage "], 21" short_name ":" batch + ", 22" update_url ": "https://clients2.google.com/service/update2/crx", 23 "version": "1.0" 24}

 

 

4. Main Write FunctionsShow_follow.js is equivalent to our entry file and can define various functions. 4.1 first define the dom button 4.2 bind button event 4.3 to be inserted into the page to obtain the xsrf value in zhihu page. Otherwise, you cannot submit the form 4.4 For batch follow-up.
JQuery (document ). ready (function ($) {var z_url = "www.zhihu.com"; var follow = {uchk_obj: $ ('. zm-profile-header-info-title '), flink: $ ('. zm-profile-side-following> '). attr ('href '), fl_btn_obj: $ ('. zg-btn-follow '), fl_them_div:' <div class = "follow_them_box" id = "follow_them_box" title = "This button is only valid on the user friend page, listen to all current newcomers "> follow them </div> ', remove_div: '<div class = "follow_them_box remove_box" id = "remove_box" title = "Clear people already listened to on the page"> remove </div>', hash_array: new Array (), uchk: function () {if (follow.uchobobj.html () = '') {return true;} else {lele.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) {}}) ;}, // Delete remove_followed: function () {$ ('# remove_box '). on ("click", function () {var temp = ''; var uid =''; // clear the listened $ ('. zg-btn-unfollow '). each (function (index, el) {temp = values (this).html (); switch (temp) {case 'unfollowed ': values ('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'display .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 ();}});
Operation Demonstration: 1. load the extension package in Chrome extension 2. click the remove button to remove the Chrome HTTP Request status of all users who can follow the current page by clicking follow them.

 

 

Listening is complete.

Source File: https://github.com/Martin-Tan/zhi-follow

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.