Created
June 3, 2011 19:08
-
-
Save to/1006960 to your computer and use it in GitHub Desktop.
action.collectFileLinks.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tombloo.Service.actions.register( { | |
name : 'Collect File Links', | |
type : 'context', | |
execute : function(ctx){ | |
var self = this; | |
var urls = {}; | |
var RE = /((anonym\.to|share|mediafire|send|upload|rapidspread)|(zip|mp3)$)/; | |
forEach(ctx.document.links, function(l){ | |
if(RE.test(l.href)) | |
urls[l.href] = true; | |
}); | |
forEach($x('//text()', ctx.document.body, true), function(l){ | |
if(/^http/.test(l) && RE.test(l)) | |
urls[l] = true; | |
}); | |
urls = keys(urls); | |
deferredForEach($x( | |
'//embed[contains(@src, "divshare.com/flash/audio_embed")]/@src', | |
ctx.document, | |
true | |
), function(src){ | |
return request('http://www.divshare.com/embed/audio_embed_xml.php?' + createURI(src).query).addCallback(function(res){ | |
urls.push(res.responseText.extract(/gallink>(.*?)<\/gallink/)); | |
}); | |
}).addBoth(function(){ | |
notify(self.name, 'Links: ' + urls.length); | |
ClipboardHelper.copyString(urls.join('\n')); | |
}); | |
}, | |
}, '----'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment