Greasy Fork

JVC contenu

Lire directement les tweets

目前为 2017-02-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         JVC contenu
// @namespace    Jvc contenu
// @version      1.0.3
// @description  Lire directement les tweets
// @author       Personne
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @match        http://www.jeuxvideo.com/forums/*
// @match        http://m.jeuxvideo.com/forums/*
// @match        http://jvforum.fr/*
// @connect      publish.twitter.com
// @connect      opengraph.io
// @grant        GM_xmlhttpRequest
// @noframes
// ==/UserScript==

(function() {
	$('.txt-msg a,.message__content-text a').each(function(){
		var regex  = new RegExp("^https?://(mobile.)?twitter\.com/[A-Za-z0-9_]{1,15}/status(es)?/([0-9]+)");
        var insta = new RegExp("^https?://(www\.)?instagram\.com/p/([A-Za-z0-9_-]+)");
        var face = new RegExp("^https:\/\/www\.facebook\.com\/([^\/?].+\/)?video(s|\.php)[\/?].*");
        var face2 = new RegExp("^https:\/\/www\.facebook\.com\/(photo(\.php|s)|permalink\.php|media|questions|notes|[^\/]+\/(activity|posts))[\/?].*");
        var youtube = new RegExp('(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})');

		var url = ($(this).attr('href'));
        var id;

        var obj = $(this);

        if(youtube.test(url)){

            match = youtube.exec(url);
            id = match[1];

              html = "<div  style='position:relative;' >";
              html += "<a style='height: 50px; left: 18%; top: 30%; position: absolute; z-index: 40; opacity: 0.7;' target='blank_' href='"+url+"'><img  style='height: 50px;' src='https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/youtube-128.png'></a>";
              html += "<a target='blank_' href='"+url+"'><img style='border-radius: 5px;max-width:250px;max-height:250px;' src='http://img.youtube.com/vi/"+id+"/mqdefault.jpg'></a></div>";
              obj.html(html);

            return true;

        }


		if(regex.test(url)){
        GM_xmlhttpRequest ( {
            method:     "GET",
            url:        "https://publish.twitter.com/oembed?url="+url,
            headers:    {"Content-Type": "application/json"},
            onload:     function (response) {
                         if(response.status == 200){
                             rep = jQuery.parseJSON(response.responseText);
                             obj.after(rep.html);
                         }

                        },
            onerror:    function () {
                        }
        } );

            return true;
		}

        if(insta.test(url)){
            match = insta.exec(url);
            id = match[1];
            if(match.length == 3){
               id = match[2];
            }
            html = "<div ><a target='blank_' href='"+match[0]+"'><img style='max-width:250px;max-height:250px;' src='https://instagram.com/p/"+id+"/media/?size=m'></a></div>";
            obj.html(html);

            return true;
        }

        if(face.test(url) || face2.test(url) ){
           match = face.exec(url);

           if(face2.test(url)){
               match = face2.exec(url);
           }
           code = "<script> function resizeIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; } </script>";
           obj.after(code);
           html = '<iframe src="https://www.facebook.com/plugins/post.php?href='+match[0]+'&width=350&show_text=true" width="350" style="width: 350px;border:none;overflow:hidden" scrolling="no" frameborder="0" onload="resizeIframe(this)" allowTransparency="true"></iframe>';
           obj.after(html);
           return true;
        }



        var getLocation = function(href) {
            var l = document.createElement("a");
            l.href = href;
            return l;
        };
        var host = getLocation(url);

        host = host.hostname.toLowerCase();
       // var liste =["timesofisrael.com", "france24.com","i24news.tv", "presstv.ir", "prestv.com", "jeuxvideo.com", "m.jeuxvideo.com","fr.sputniknews.com","entreprendre.fr", "lorientlejour.com","francais.rt.com", "gameblog.fr","gamekult.com", "fr.wikipedia.org","en.wikipedia.org", "thesun.co.uk", "jeanmarcmorandini.com", "franceinter.fr", "lemonde.fr", "mobile.lemonde.fr", "mediapart.fr", "blogs.mediapart.fr", "lefigaro.fr","bfmbusiness.bfmtv.com","bfmtv.com", "marianne.net", "numerama.com", "buzzfeed.com", "tv5.org","01net.fr","20minutes.fr","challenges.fr","dna.fr","europe1.fr","france2.fr","france3.fr","france5.fr","latribune.fr","leparisien.fr","lepoint.fr","lepost.fr","Lequipe.fr","lesechos.fr","letelegramme.fr","lexpress.fr","liberation.fr","nouvelobs.com","parismatch.com","radiofrance.fr","rfi.fr","rue89.com","sudouest.fr","telerama.fr","TF1.fr","agoravox.fr","capital.fr","ladepeche.fr","lanouvellerepublique.fr","laprovence.com","lavoixdunord.fr","ledauphine.com","lejdd.fr","leprogres.fr","lesinrocks.com","m6.fr","marianne2.fr","mediapart.fr","nicematin.com","ouest-france.fr","owni.fr","rmc.fr","rtl.fr","slate.fr","maville.com","midilibre.com","metrofrance.com"];

        var  liste = ["goo.gl", "vid.me", "issoutv.com", "webm.land", "noelshack.com", "image.noelshack.com", "i.imgur.com", "vimeo.com", "hapshack.com", "puu.sh", "dailymotion.com"];

        host = host.replace('www.','');

        if((liste.indexOf(host) == -1)){

            var urlEncoded = encodeURIComponent(url);
            var apiKey = "A MODIFIER";


            var requestUrl = 'http://opengraph.io/api/1.0/site/' + urlEncoded ;

            if(apiKey){
                requestUrl = 'https://opengraph.io/api/1.0/site/' + urlEncoded + '?app_id=' + apiKey;
            }

            GM_xmlhttpRequest ( {
                method:     "GET",
                url:        requestUrl,
                headers:    {"Content-Type": "application/json"},
                onload:     function (response) {
                    if(response.status == 200){
                        json = jQuery.parseJSON(response.responseText);

                        if (typeof json.hybridGraph.title !== 'undefined') {
                            html = '<a href="'+url+'" target="_blank" style="text-decoration:none;color:black">';

                            console.log(json);
                            if (typeof json.hybridGraph.image !== 'undefined') {
                                html += '<div style="margin-top:5px;margin-bottom:5px;padding:5px;border:1px solid #dedede;background: #f9f9f9;">';
                                html += '<div class="ope-img" style="margin-right:10px;float: left;height:90px;width:170px; background:url(\''+json.hybridGraph.image+'\') no-repeat ; background-size: cover;background-position: center;">';
                                html += '</div>';
                            }

                            html += '<div class="contenu" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;height:90px;">';
                            html += '<div class="title" title="'+json.hybridGraph.title +'" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;font-weight:bold;margin-bottom:10px;">'+json.hybridGraph.title+'</div>';
                            html += '<div class="description" title="'+json.hybridGraph.description +'" style="height: 50px; overflow: hidden;font-size: 11.5px;white-space: normal; ">'+json.hybridGraph.description+'</div>';
                            html += '<div style="font-size: 8px; float: right; bottom: 5px; color: gray;">'+host+'</div>';
                            html += '</div>';
                            html += '</div></a>';

                            obj.html(html);
                        }

                    }

                },
                onerror:    function () {
                }
            } );

        }


	});
})();