This is the first day of my participation in the More text Challenge. For details, see more text Challenge

Recently has been reading novels on the Chinese website of starting point, suddenly found that the official even sell automatic sign-in card, five yuan a month! How can a programmer spend all this money?!

The idea of writing a script began.

Step 1: Try to simulate clicking buttons regularly

The ‘claimed’ in the picture is a red button before the claim!!

  1. Tried to write JS directly in the console, feasible but not completely feasible, because each click to receive after the refresh page; We had to find another way.
  2. At some point, you’d have to find a plug-in to automatically inject the code. So, I reinvented a plugin that I hadn’t used in a long time and put this code in. Perfect! Good!

However, there is a problem with this. Although it is implemented, it does not understand how the Google plugin is developed.

Step 2: Search the Google Plugin development documentation all over the web

After some searching, I found the best document for writing this script right now.

English documents are best to find, Google a search can be found, need to climb the wall.

Chinese documents are uneven, finally found a very good blog, if there is a need to point a like, [dry goods] Chrome plug-in (extension) development overview

Step 3: Start the development, the functional logic is not complex, just a way of thinking

I have uploaded the code to GitHub, if you are interested you can go to start. The link is here: pxyzexp-qidian

The code directory is as follows:

**_locales: ** was introduced for international purposes, but it doesn’t need to be introduced here, other countries probably don’t use the starting point to read novels.

**img: ** save the icon

**js: **js file

**background.html: ** continuous HTML running in the background (resident)

**manifest. Json: ** Core configuration file, this is the most important

**popup. HTML: ** The page displayed by the icon in the upper right corner of the browser

I’ll focus on three files: manifest.json, content-script.js, and popup.html

Manifest.json (sure, all configuration parameters of the plugin are in this) :

// Here is my configuration. {" Manifest_version ": 2, // The manifest_version file must be written and must be 2 "name": "pxyzexp-qidian", // the plug-in name" version": "/ / plug-in version 1.0.0", "description" : "starting point automatic check-in tools", "background" : {/ / plug-in background "page" : "background. HTML"}, "ICONS" : / / the plugin icon {" 48 ": "Img /icon.png", "128": "img/icon.png"}, "browser_action": // set the upper right corner of the browser icon {"default_icon": "Img /icon.png", "default_title":" start automatic check-in tool ", "default_popup": "popup.html" // the icon in the upper right corner of the browser displays the page}, "content_scripts": {/ / "< all_urls >" : match all address "matches" : [" * https://my.qidian.com/level/ "], / / multiple JS sequential injection "JS" : ["js/content-script.js"], // Code injection time "run_at": "document_end"}], // Default language "default_locale": "zh_CN"}Copy the code

Content-script.js (js injection, automatically click the button to check in the script here)

(function() {function() {if (function() {if (function() { SetInterval (function(){var demo = document.getelementById ('elTaskWrap'); var liEle = demo.getElementsByTagName('li'); for(var i=0; i<liEle.length; I ++){var aEle = liEle[I].getelementsbyTagName ('a'); if(aEle.length ! = 0){ aEle[0].click(); }}}, 1000); // Refresh the page regularly, in case the page is stuck, or the calculation of the problem, after a period of time refresh, start again. SetInterval (function(){console.log(new Date()+" refresh "); window.location.reload(); }, 600000); }) ();Copy the code

Popup.html (icon display page, one image suffice)

Step 4: Summarize

I’ve always wanted to explore Chrome add-ons, but I haven’t had a single business scenario, so this is a first taste, and I may need more in the future.

Welcome to Github to start the project…

Everyone come on, the green mountains do not change, the green water flows, the river’s lake goodbye.