gt22

Untitled

Nov 6th, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.70 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>ITHappedns</title>
  6.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  7.     <style>
  8.         .mainButton, .mainButton:focus {
  9.             background: none;
  10.             border: none;
  11.             outline: none;
  12.         }
  13.         a {
  14.             text-decoration: none;
  15.         }
  16.     </style>
  17.     <script>
  18.         //Enable cross-origin ajax
  19.         jQuery.ajax = (function(_ajax){
  20.  
  21.             var protocol = location.protocol,
  22.                     hostname = location.hostname,
  23.                     exRegex = new RegExp(protocol + '//' + hostname),
  24.                     YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
  25.                     query = 'select * from html where url="{URL}" and xpath="*"';
  26.  
  27.             function isExternal(url) {
  28.                 return !exRegex.test(url) && /:\/\//.test(url);
  29.             }
  30.  
  31.             return function(o) {
  32.  
  33.                 var url = o.url;
  34.  
  35.                 if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
  36.  
  37.                     // Manipulate options so that JSONP-x request is made to YQL
  38.  
  39.                     o.url = YQL;
  40.                     o.dataType = 'json';
  41.  
  42.                     o.data = {
  43.                         q: query.replace(
  44.                                 '{URL}',
  45.                                 url + (o.data ?
  46.                                 (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
  47.                                         : '')
  48.                         ),
  49.                         format: 'xml'
  50.                     };
  51.  
  52.                     // Since it's a JSONP request
  53.                     // complete === success
  54.                     if (!o.success && o.complete) {
  55.                         o.success = o.complete;
  56.                         delete o.complete;
  57.                     }
  58.  
  59.                     o.success = (function(_success){
  60.                         return function(data) {
  61.  
  62.                             if (_success) {
  63.                                 // Fake XHR callback.
  64.                                 _success.call(this, {
  65.                                     responseText: (data.results[0] || '')
  66.                                     // YQL screws with <script>s
  67.                                     // Get rid of them
  68.                                             .replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
  69.                                 }, 'success');
  70.                             }
  71.  
  72.                         };
  73.                     })(o.success);
  74.  
  75.                 }
  76.  
  77.                 return _ajax.apply(this, arguments);
  78.  
  79.             };
  80.  
  81.         })(jQuery.ajax);
  82.         //End of enabling
  83.         var curStoryID;
  84.         var user;
  85.         function login(usr) {
  86.             if(usr == null)
  87.                 usr = $("#user").val();
  88.             $.post("php/ith.php", {mode: "get", login: usr}, function (data) {
  89.                 curStoryID = parseInt(data);
  90.                 $("#login").css("display", "none");
  91.                 var postLogin = $("#postLogin");
  92.                 postLogin.css("display", "block");
  93.                 if(isNaN(curStoryID))
  94.                 {
  95.                     postLogin.html(data);
  96.                     return;
  97.                 }
  98.                 getStory(curStoryID - 1, function (data) {
  99.                     $("#story").html(data);
  100.                 });
  101.                 user = usr;
  102.                 localStorage.setItem("user", usr);
  103.             });
  104.         }
  105.        
  106.         function setId(id) {
  107.             curStoryID = id;
  108.             $.post("php/ith.php", {mode: "set", login: user, id: id}, function (data) {
  109.                 if(data !== "Succes")
  110.                 {
  111.                     $("#errors").html(data);
  112.                 }
  113.             });
  114.             getStory(curStoryID - 1, function (data) {
  115.                 $("#story").html(data);
  116.             });
  117.         }
  118.  
  119.         function getStory(id, callback) {
  120.             $.get("http://ithappens.me/story/" + id, function (data) {
  121.                 var story = document.createElement("html");
  122.                 story.innerHTML = data.responseText;
  123.                 story = $(".story", story);
  124.                 callback("" +
  125.                         "<h1><a href='http://ithappens.me/story/" + id + "'>" + id + ":" + $("h1", story).html() + "</a></h1>" +
  126.                         "<div>" +
  127.                         $(".text", story).html() +
  128.                         "</div>");
  129.             })
  130.         }
  131.         $(function () {
  132.             var usr = localStorage.getItem("user");
  133.             if(usr != undefined && usr != null)
  134.             {
  135.                 login(usr);
  136.             }
  137.         })
  138.     </script>
  139. </head>
  140. <body>
  141. <div>
  142.     <div id="login">
  143.         <label for="user"></label>
  144.         <input type="text" id="user">
  145.         <button onclick="login(null)">login</button>
  146.     </div>
  147.     <div id="postLogin" style="display: none">
  148.         <div id="story">
  149.  
  150.         </div>
  151.         <div id="buttons">
  152.             <button onclick="setId(curStoryID - 1)" class="mainButton">
  153.                 <- Сюда
  154.             </button>
  155.             <button onclick="setId(curStoryID + 1)" class="mainButton">
  156.                 Туда ->
  157.             </button>
  158.         </div>
  159.         <div id="errors"></div>
  160.     </div>
  161. </div>
  162. </body>
  163. </html>
Advertisement
Add Comment
Please, Sign In to add comment