Changeset 9715
- Timestamp:
- 04/18/08 20:29:40 (5 years ago)
- Files:
-
- 1 modified
-
lang/javascript/userscripts/weheartit.user.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/weheartit.user.js
r9704 r9715 11 11 var D = window.Minibuffer.D; 12 12 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){ 14 36 window.Minibuffer.status('WeHeartItCommand', 'I Heart It ...'); 15 37 … … 17 39 title = title.replace(/'+/g, ""); 18 40 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) 23 42 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 }) 25 50 .next(function(){ 26 51 window.Minibuffer.status('WeHeartItCommand', 'I Heart It ... done.', 100); … … 49 74 if(typeof obj != 'object') return; 50 75 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) {} 51 81 try { 52 82 var elems = obj.getElementsByTagName("img"); … … 55 85 } catch(e) {} 56 86 with(D()) { 57 parallel(images.map( heartit))87 parallel(images.map(function(i){return {url:url,image:i}}).map(heartit)) 58 88 .wait(2) 59 89 .next(function(){window.Minibuffer.status('WeHeartItCommand', 'Everything is OK', 1000)});
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)