Changeset 9715

Show
Ignore:
Timestamp:
04/18/08 20:29:40 (5 years ago)
Author:
mattn
Message:

lang/javascript/userscripts/weheartit.user.js:

  • リンク先のタイトルを見に行くように修正
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/weheartit.user.js

    r9704 r9715  
    1111        var D  = window.Minibuffer.D; 
    1212 
    13         function heartit(img){ 
     13        function convertToHTMLDocument(html){ 
     14                var xsl = (new DOMParser()).parseFromString( 
     15                        '<?xml version="1.0"?>\ 
     16                                        <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">\ 
     17                                        <output method="html"/>\ 
     18                                </stylesheet>', "text/xml"); 
     19                var xsltp = new XSLTProcessor(); 
     20                xsltp.importStylesheet(xsl); 
     21                var doc = xsltp.transformToDocument(document.implementation.createDocument("", "", null)); 
     22                doc.appendChild(doc.createElement("html")); 
     23                var range = doc.createRange(); 
     24                range.selectNodeContents(doc.documentElement); 
     25                doc.documentElement.appendChild(range.createContextualFragment(html)); 
     26                return doc; 
     27        } 
     28 
     29        function getSource(url){ 
     30                with(D()){ 
     31                        return xhttp.get(url) 
     32                } 
     33        } 
     34 
     35        function heartit(ctx){ 
    1436                window.Minibuffer.status('WeHeartItCommand', 'I Heart It ...'); 
    1537 
     
    1739                title = title.replace(/'+/g, ""); 
    1840                title = title.replace(/&/g, "_"); 
    19                 var via = unescape(location.href); 
    20  
    21                 var url = "http://weheartit.com/add.php?title=" + title + "&via=" + via + "&img=" + img.src; 
    22  
     41                getSource(ctx.url) 
    2342                var d = D(); 
    24                 d.xhttp.get(url) 
     43                d.xhttp.get(ctx.url) 
     44                .next(function(res){ 
     45                        var via = unescape(ctx.url); 
     46                        var title = $X('//title', convertToHTMLDocument(res.responseText))[0].textContent; 
     47                        var post_url = "http://weheartit.com/add.php?title=" + title + "&via=" + via + "&img=" + ctx.image.src; 
     48                        return d.xhttp.get(post_url); 
     49                }) 
    2550                .next(function(){ 
    2651                        window.Minibuffer.status('WeHeartItCommand', 'I Heart It ... done.', 100); 
     
    4974                                if(typeof obj != 'object') return; 
    5075                                var images = []; 
     76                                var url = location.href; 
     77                                if (window.LDRize) try { 
     78                                        var xpath = window.LDRize.getSiteinfo()['link']; 
     79                                        if (xpath) url = $X(xpath, obj)[0].href; 
     80                                } catch(e) {} 
    5181                                try { 
    5282                                        var elems = obj.getElementsByTagName("img"); 
     
    5585                                } catch(e) {} 
    5686                                with(D()) { 
    57                                         parallel(images.map(heartit)) 
     87                                        parallel(images.map(function(i){return {url:url,image:i}}).map(heartit)) 
    5888                                        .wait(2) 
    5989                                        .next(function(){window.Minibuffer.status('WeHeartItCommand', 'Everything is OK', 1000)});