Simple voting system and js ticketing ideas and methods, voting system js ticketing ideas

Source: Internet
Author: User

Simple voting system and js ticketing ideas and methods, voting system js ticketing ideas

I have long heard of some vote-related scripts, Weibo voting, and so on.

Could you give it a try? Maybe you will also get a ticket? After a few hours, I finally got a glimpse.

(1) Voting System

You have to have a vote page first.

Of course, you can directly go to the various voting websites, but here we will create a voting page for your convenience.

The page is roughly as follows or you can view the demo

The page is concise, but the basic voting function is also available.

The original rule is: only one vote can be cast, a prompt is displayed, and the button is unavailable.

All are native JS, and DOM operations are not flexible. Of course, it will be very convenient to use jq.

Html/css

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Js Section

<Script type = "text/javascript"> function getElemensByClassName (className) {// obtain var classArr = new Array () through class; var tags = document. getElementsByTagName ("*"); // obtain all nodes for (var item in tags) {if (tags [item]. nodeType = 1) {if (tags [item]. getAttribute ("class") = className) {classArr. push (tags [item]); // collect nodes matching the class }}return classArr;} function delete_FF (element) {// Delete the element var childs whose child node is empty in FireFox = Element. childNodes; for (var I = 0; I <childs. length; I ++) {var pattern =/\ s/; // pattern matching. The content is null if (childs [I]. nodeName = "# text" & pattern. test (childs [I]. nodeValue) {// process // alert (childs [I]. nodeName); element. removeChild (childs [I]); // Delete the empty node retrieved from FF }}} window. onload = function () {var persons = getElemensByClassName ("person"); // alert (persons); for (var item in persons) {// traverse all persons, bind a voting event (function (_ it Em) {// The anonymous function imports the item to prevent the item from being the last delete_FF (persons [_ item]) due to scope issues; // out-of-the-box FF hollow row represents the subnode persons [_ item]. setAttribute ("id", "person" + (parseInt (_ item) + 1); // assign id var childs = persons [_ item]. childNodes; for (var I = 0; I <childs. length; I ++) {// alert (childs [I]. nodeName); if (childs [I]. nodeName = "BUTTON") {// click the BUTTON to vote var oButton = childs [I];} if (childs [I]. nodeName = "P") {// var oP = childs [I]; var oSpan = OP. getElementsByTagName ("span") [0] ;}} if (oButton! = Null) {oButton. onclick = function () {// event binding var num = oSpan. innerHTML; // obtain the number of votes oSpan. innerHTML = (++ num); // Number of votes updated // in this case, we may need to transfer the number of votes num to the server for storage. this is also synchronized with the num in the server during the update. setAttribute ("disabled", "true"); // you can only vote for alert once ("Vote successful, thank you for your support ");};}}) (item); // enter the person of each item }}; </script>

Note should be clear, a simple voting page.

(2) ticket flushing script implementation

The vote script means to vote through the script. How can we vote?

Through the above Code, we know that a general vote is to click "Vote" to process the data.

The front-end has a count num and the back-end has a count num. They are synchronized. We don't need to care about the back-end num because the front-end and the back-end are synchronized.

When the click event is triggered, js will naturally synchronize num. We need to refresh the ticket. In fact, it is enough to trigger the click event.

In addition, the voting system is a page of another user, and we do not have the right to modify it. What we can do is simulate an event through js.

So how can I use the script?

Generally, the console mode is used. For example, in the FireFox Chrome console, the script written by the user is put, and it will parse and execute the script to process page data.

For example, in the FireBug console, information is displayed on the left and js Code can be entered on the right.

Alternatively, you can use the chrome console. Just enter js and press enter to execute it.

If you haven't used any of these shoes, you can search for related knowledge.

Write a simple ticket flushing script.

First of all, we follow the regular method, assuming that the voting page is not written by us, how do we brush votes?

We must find out the key points of voting.

Find the review element, which is usually the voting button.

Click that and move the mouse to the voting page. How can this problem be solved? Search for other tag information, such as id class, on the page for convenience.

OK. determine the relevant information, id tag type, and so on.

Now, I want to give two a vote and send it once every two seconds. My goal is to keep two's total number of votes greater than three (of course, whatever you want)

Let's start writing code. We get used to jquery and can also be used directly in the console.

Or if the old version does not support jquery, add the following in the Code:

javascript:(function(url) {  var s = document.createElement('script');  s.src = url;  (document.getElementsByTagName('head')[0] ||    document.getElementsByTagName('body')[0]).appendChild(s);})('http://code.jquery.com/jquery-2.1.3.js');

Official start

1. Write a universal ticket flushing Function

Function brushVotes () {// fl function var t = setInterval (function () {var three_num = $ ("# person3> p> span "). text (); // number of three votes var two_num = $ ("# person2> p> span "). text (); // two votes console.info (two_num + "" + three_num); if (two_num-three_num <5) {// keep the advantage of 5 votes ahead $ ("# person2> button "). click (). attr ("disabled", false); // click the event that triggers the voting. After the vote is completed, remember to get the voting permission back.} if (two_num-three_num = 5) {// 5 votes lead to clearInterval (t); }}, 2000 );}

Use a timer to execute a voting event every two seconds. The ticket will be suspended after the 5-vote lead.

2. Call the ticket flushing Function

The initial call is performed once. When you click Run, the script is executed.

Then listen to the change in the number of three votes and bind the ticket.

A normal change event can only be supported by TAG elements related to the form. Of course, we can change the span in the number of votes to the input tag so that it has an onchange event.

But the page is owned by others, and we cannot change it.

So find out and finally find another method to detect changes in TAG content such as div span. If you want to understand this method in depth, welcome

BrushVotes (); // canvassing $ ("# person3> p> span "). bind ('domainserted', function (e) {// three change triggers brushVotes (); // continue to vote });

As a result, the number of votes in three changes, and the ticket will be automatically triggered to continue to be flushed.

Complete script

Javascript :( function (url) {var s = document. createElement ('script'); s. src = url; (document. getElementsByTagName ('head') [0] | document. getElementsByTagName ('body') [0]). appendChild (s) ;}) ('HTTP: // code.jquery.com/jquery-2.1.3.js'); brushVotes (); // Ticket $ ("# person3> p> span "). bind ('domainserted', function (e) {// three change triggers brushVotes (); // continue to vote}); function brushVotes () {// function var t = setInterval (function () {var three_num = $ ("# person3> p> span "). text (); // number of three votes var two_num = $ ("# person2> p> span "). text (); // two votes console.info (two_num + "" + three_num); if (two_num-three_num <5) {// keep the advantage of 5 votes ahead $ ("# person2> button "). click (). attr ("disabled", false); // click the event that triggers the voting. After the vote is completed, remember to get the voting permission back.} if (two_num-three_num = 5) {// 5 votes lead to clearInterval (t); }}, 2000 );}

Finally, simulate

1. Go to the voting page, call up Firebug, and type the complete code in the code input area on the right of the console.

2. Click "run" in the upper left corner, And let two refresh from scratch to 5. 5 votes ahead of three.

In this way, alert is used for five times.

3. Then, someone in the simulation gave three a vote and clicked the three button.

4. The number of three votes has changed, and two continues to brush votes.

5. Finally, the ticket is suspended after 6 votes are refreshed.

Bytes ------------------------------------------------------------------------------------------------------

This is a simple ticket flushing script implementation.

Through this, we need to learn how to use our scripts to operate on others' pages. Of course, this is not the same as the so-called Script Injection ..

All we do is simulate normal page events and manually trigger them.

Through this mechanism, not only can the vote system be flushed, but also the brute force authentication login .. however, if you encounter a huge loss of verification codes, you can also use the script to grab tickets .. however, more knowledge should be involved.

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.