📜 ⬆️ ⬇️

Personal ranking of deputies each using JavaScript and Chrome browser

Soon some of us will go to cast votes for the next candidates for deputies. Deputies are our representatives and we give them the right to make some legislative decisions for us. In these conditions, it is logical to choose those who make their choice as we do.


The votes of the deputies are on vote.duma.gov.ru. It remains for us to vote for important bills for us in accordance with our vision and get a rating based on which and make a choice in elections.


I chose the least expensive path and wrote a JavaScript extension for Chrome. Work with it is organized through the browser console (Ctrl + Shift + J). As a bonus, I tested the support of the Russian language in JavaScript without preprocessors.


Under the cut you are waiting for the code with comments and comments on the article.



In the folder "vote" there are three files "manifest.json", "insert.js", "script.js" in UTF-8 encoding (without BOM).


Code:


File "manifest.json":


{ "manifest_version": 2, "name": " ", "description": "       vote.duma.gov.ru", "version": "1.0", "content_scripts": [ { "matches": [ "http://vote.duma.gov.ru/*" ], "js": [ "insert.js" ], "run_at": "document_end" } ], "web_accessible_resources": [ "script.user.js" ] } 

The "web_accessible_resources" manifest part allows the page to access and use the plugin files listed in it. "script.js" is the main script in which all the logic.


Chrome does not give direct access to page variable extensions. We embed our script ("script.js") into the page itself using "insert.js".


File "insert.js":


 var script = document.createElement('script'); script.type = 'text/javascript'; script.src = chrome.extension.getURL("script.user.js"); script.async = 1; document.head.appendChild(script); 

File "script.user.js":


 // ==UserScript== // @name   // @description        vote.duma.gov.ru // @author ivan386 // @license MIT // @version 1.0 // @run-at document-end // @include http://vote.duma.gov.ru/* // ==/UserScript== javascript: (function() { 'use strict'; 

 var  = function(  ){ console.log(  ); document.querySelector( "#" ).innerText = ; }; 

 var  = function( _ ) { if ( typeof deputiesData !== 'undefined' ) { /*         localStorage */ var  = JSON.parse( localStorage.getItem( "" ) || "{}" ); /*   deputiesData         . */ deputiesData.forEach( function(  ) { var ls_ = [ .url ]; /*      0 */ . = ( !ls_ ) ? 0 : ls_.; /*   */ . = ( !ls_ ) ? {} : ( ls_. || {} ); /*   */ . = .sortName; /*      . */ if ( typeof( .[ .result ] ) === 'undefined' ) .[ .result ] = 1; else .[ .result ] ++; . = 0; for ( var  in . ) . += .[]; /*        ID    . */ /*     . */ [ .url ] = ; /*        result */ /*     renderer        vote.duma.gov.ru. */ /*  -1   "" */ /*  0   "" */ /*  1   "" */ /*  2   " " */ /*        . */ . += ( .result == _ ) ? 1 : -1; } ); /*      localStorage */ localStorage.setItem( "" , JSON.stringify(  ) ); ( " " + ( _ == -1 ? "" : "" ) + " " ); } else ( "        " ); }; 

 var  = function() { /*  -1   "" */ return ( -1 ); }; 

 var  = function() { /*  1   "" */ return ( 1 ); }; 

 var _ = function(  ) { var __ = []; var  = []; for ( var  in  ) __.push( [  ] ); __.sort( function( ,  ) { /*      */ return . - .; } ); __.forEach( function(  ) { /*     */ .push( . + ": " + . + ( . ? " (" + . + ")" : "" ) ); } ); return .join( "\n" ); }; 

 var _ = function() { var  = JSON.parse( localStorage.getItem( "" ) || "{}" ); ( _(  ) ); }; 

 var _ = function() { var  = JSON.parse( localStorage.getItem( "" ) || "{}" ); var  = {}; for ( var  in  ) { var  = [  ]; var  = [ .factionCode ]; if (  ) { /*      . */ . += .; . ++; } else [ .factionCode ] = { : .faction , : . , : 1 }; } ( _(  ) ); }; 

 var  = (typeof unsafeWindow === 'undefined') ? window : unsafeWindow; document.body.insertBefore( document.createElement( "div" ) , document.body.firstChild ).innerHTML = ' :\n\ <button onclick="()"></button>\n\ <button onclick="()"></button>\n\ <button onclick="_()"> </button>\n\ <button onclick="_()"> </button>\n\ <div id=""></div>'; . = ; . = ; ._ = _; ._ = _; if ( typeof( .deputiesData ) !== 'undefined' ) deputiesData = .deputiesData; ( "() -  \n\ () -  \n\ _() -         \n\ _() -         \n\ " ); })(); void(0); 

Installation


  1. Copy the folder "vote" with the contents on a local disk.
  2. In the Chrome browser, open "chrome: // extensions /" or "Main Menu> Additional Tools> Extensions"
  3. Put a tick "Developer Mode"
  4. Click "Download unpacked extension ..."
  5. Find and select the folder "vote" with scripts.
  6. Click OK.

Using


We vote

  1. Go to the page with the votes of deputies on vote.duma.gov.ru.
    For example: http://vote.duma.gov.ru/vote/95967 (link taken here )
  2. Open the browser console (Ctrl + Shift + J).
    3.1. If against we write:


     () 

    3.2. If for we write:


     () 

  3. Press Enter

We get a rating

  1. Go to any vote.duma.gov.ru page.
  2. Open the browser console (Ctrl + Shift + J) is not yet open.
    3.1. To display the deputies rating:


     _() 

    3.2. To display the rating of parties:


     _() 

  3. Press Enter

Or you can use the buttons at the top of the page.


Result


As a result, each user of this script receives its rating of deputies and parties in accordance with their choice and the choice of deputies.


Example of deputies rating:


   : 5   : 0   : -5 

Example of party rating (in brackets the number of deputies):


 : 100 (10) : 0 (1) : -100 (1) 

All names and events are fictional. Matches are random.


Conclusion


I hope this script will help you make a more informed choice of your representative in the legislative branch. And at the same time, it will also show an example of writing an extension for analyzing data on state sites.


I ask to write about errors in private messages.


Sources


  1. Create your own extension for Google Chrome
  2. How to run Chrome extensions not from the WebStore
  3. Learning to write userscript
  4. Scripts on GitHub
  5. System of analysis of voting results at State Duma meetings

')

Source: https://habr.com/ru/post/306744/


All Articles