gt22 icon

Untitled

gt22 | PRO | 11/06/16 05:20:27 PM UTC | 0 ⭐ | 658 👁️ | Never ⏰ | []
HTML 5 |

0 B

|

None

|

0 👍

/

0 👎

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ITHappedns</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <style>
        .mainButton, .mainButton:focus {
            background: none;
            border: none;
            outline: none;
        }
        a {
            text-decoration: none;
        }
    </style>
    <script>
        //Enable cross-origin ajax
        jQuery.ajax = (function(_ajax){
 
            var protocol = location.protocol,
                    hostname = location.hostname,
                    exRegex = new RegExp(protocol + '//' + hostname),
                    YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
                    query = 'select * from html where url="{URL}" and xpath="*"';
 
            function isExternal(url) {
                return !exRegex.test(url) && /:\/\//.test(url);
            }
 
            return function(o) {
 
                var url = o.url;
 
                if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
 
                    // Manipulate options so that JSONP-x request is made to YQL
 
                    o.url = YQL;
                    o.dataType = 'json';
 
                    o.data = {
                        q: query.replace(
                                '{URL}',
                                url + (o.data ?
                                (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
                                        : '')
                        ),
                        format: 'xml'
                    };
 
                    // Since it's a JSONP request
                    // complete === success
                    if (!o.success && o.complete) {
                        o.success = o.complete;
                        delete o.complete;
                    }
 
                    o.success = (function(_success){
                        return function(data) {
 
                            if (_success) {
                                // Fake XHR callback.
                                _success.call(this, {
                                    responseText: (data.results[0] || '')
                                    // YQL screws with <script>s
                                    // Get rid of them
                                            .replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
                                }, 'success');
                            }
 
                        };
                    })(o.success);
 
                }
 
                return _ajax.apply(this, arguments);
 
            };
 
        })(jQuery.ajax);
        //End of enabling
        var curStoryID;
        var user;
        function login(usr) {
            if(usr == null)
                usr = $("#user").val();
            $.post("php/ith.php", {mode: "get", login: usr}, function (data) {
                curStoryID = parseInt(data);
                $("#login").css("display", "none");
                var postLogin = $("#postLogin");
                postLogin.css("display", "block");
                if(isNaN(curStoryID))
                {
                    postLogin.html(data);
                    return;
                }
                getStory(curStoryID - 1, function (data) {
                    $("#story").html(data);
                });
                user = usr;
                localStorage.setItem("user", usr);
            });
        }
        
        function setId(id) {
            curStoryID = id;
            $.post("php/ith.php", {mode: "set", login: user, id: id}, function (data) {
                if(data !== "Succes")
                {
                    $("#errors").html(data);
                }
            });
            getStory(curStoryID - 1, function (data) {
                $("#story").html(data);
            });
        }
 
        function getStory(id, callback) {
            $.get("http://ithappens.me/story/" + id, function (data) {
                var story = document.createElement("html");
                story.innerHTML = data.responseText;
                story = $(".story", story);
                callback("" +
                        "<h1><a href='http://ithappens.me/story/" + id + "'>" + id + ":" + $("h1", story).html() + "</a></h1>" +
                        "<div>" +
                        $(".text", story).html() +
                        "</div>");
            })
        }
        $(function () {
            var usr = localStorage.getItem("user");
            if(usr != undefined && usr != null)
            {
                login(usr);
            }
        })
    </script>
</head>
<body>
<div>
    <div id="login">
        <label for="user"></label>
        <input type="text" id="user">
        <button onclick="login(null)">login</button>
    </div>
    <div id="postLogin" style="display: none">
        <div id="story">
 
        </div>
        <div id="buttons">
            <button onclick="setId(curStoryID - 1)" class="mainButton">
                <- Сюда
            </button>
            <button onclick="setId(curStoryID + 1)" class="mainButton">
                Туда ->
            </button>
        </div>
        <div id="errors"></div>
    </div>
</div>
</body>
</html>

Comments