PageRenderTime 45ms CodeModel.GetById 15ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/autolink_to_unsw_library_proxy.user.js

http://gsbabil.googlecode.com/
JavaScript | 198 lines | 130 code | 16 blank | 52 comment | 7 complexity | f6bef221fc9a4f61e13eedf489f05cba MD5 | raw file
  1// ==UserScript==
  2// @name           AutoLink to UNSW Library Proxy
  3// @description    Rewrites links to download conference papers through UNSW library proxy.
  4// @include        http://ieeexplore.ieee.org/*
  5// @include        http://springerlink.metapress.com/*
  6// @include        http://www.springerlink.com/*
  7// @include        http://portal.acm.org/*
  8// @include        http://www.sciencedirect.com/*
  9// ==/UserScript==
 10
 11SITES = 
 12[
 13	/*
 14	 *
 15	 * Basic Idea: 
 16	             	Rewrite the URL's that leads to "Purchase PDF" on sites like IEEExplore, 
 17			SpringerLink, ACM such that they point to URL's through UNSW Library proxy 
 18			which lets you download these PDF's for free as long as you are a student
 19			with them.
 20				  
 21	 * Why:
 22			Reduce the number of clicks, mouse-keyboard actions before you get hold of
 23			the desired PDF and start reading.
 24				  
 25			They are free for the UNSW students anyway. You shouldn't have to perform 
 26			10 clicks and keyboard actions before you get them.
 27				  
 28			With this script installed in GreaseMonkey, you can just ...
 29				- search in Google for your conference paper
 30				- click on the ACM/Springer/IEEE link
 31				- Once you see the monkey icon (yes, that's right) your PDF is ready to
 32				  download.
 33	
 34	 * Adding Your Own Site:
 35	 
 36	{
 37		url_snip:	"if this variable matches with current URL, actions to re-write link(s) begin",
 38		tag_name:	"name of the tag containing the target href",
 39		href_pattern:	"this variable is searched over all anchors (<a href>) for which the link need to be re-written upon a match",
 40		snr_pattern: 	[
 41					{ 
 42						search:		"pattern-to-search-for",
 43						replace:	"pattern-to-replace-with",
 44					},
 45					{ 
 46						search:		"more-pattern-to-search-for",
 47						replace:	"more-pattern-to-replace-with",
 48					},
 49				]
 50	},
 51	*
 52	*
 53	*/
 54
 55	{
 56		url_snip:	"sciencedirect.com",
 57		tag_name:	"a",		
 58		href_pattern:	"sdarticle.pdf",
 59		snr_pattern: 	[
 60					{ 
 61						search:		"http://www.sciencedirect.com",
 62						replace:	"http://www.sciencedirect.com.wwwproxy0.library.unsw.edu.au",
 63					},
 64				]
 65	},	
 66	{
 67		url_snip:	"ieeexplore",
 68		tag_name:	"a",
 69		href_pattern:	"stamp.jsp",
 70		snr_pattern:	[
 71					{
 72						search:		"http://ieeexplore.ieee.org",
 73						replace:	"http://ieeexplore.ieee.org.wwwproxy0.library.unsw.edu.au",
 74					},
 75				]
 76	},
 77	{
 78		url_snip:	"ieeexplore",
 79		tag_name:	"a",		
 80		href_pattern:	"Sarticle.jsp",
 81		snr_pattern: 	[
 82					{ 
 83						search:		"http://ieeexplore.ieee.org",
 84						replace:	"http://ieeexplore.ieee.org.wwwproxy0.library.unsw.edu.au",
 85					},
 86					{ 
 87						search:		"articleSale/Sarticle.jsp",
 88						replace:	"stamp/stamp.jsp",
 89					},
 90				]
 91	},
 92	{
 93		url_snip:	"springerlink.*metapress",
 94		tag_name:	"a",		
 95		href_pattern:	"fulltext",
 96		snr_pattern: 	[
 97					{ 
 98						search:		"http://springerlink.metapress.com",
 99						replace:	"http://springerlink.metapress.com.wwwproxy0.library.unsw.edu.au",
100					},
101				]
102	},
103	{
104		url_snip:	"www.*springerlink",
105		tag_name:	"a",		
106		href_pattern:	"fulltext",
107		snr_pattern: 	[
108					{ 
109						search:		"http://www.springerlink.com",
110						replace:	"http://www.springerlink.com.wwwproxy0.library.unsw.edu.au",
111					},
112				]
113	},
114
115	{
116		url_snip:	"portal.acm",
117		tag_name:	"a",		
118		href_pattern:	"purchase.cfm",
119		snr_pattern: 	[
120					{ 
121						search:		"http://portal.acm.org",
122						replace:	"http://portal.acm.org.wwwproxy0.library.unsw.edu.au",
123					},
124					{ 
125						search:		"purchase.cfm?",
126						replace:	"ft_gateway.cfm?type=pdf&",
127					},
128				]
129	},
130	{
131		url_snip:	"portal.acm",
132		tag_name:	"a",		
133		href_pattern:	"ft_gateway.cfm.*type=pdf&coll=DL",
134		snr_pattern: 	[
135					{ 
136						search:		"http://portal.acm.org",
137						replace:	"http://portal.acm.org.wwwproxy0.library.unsw.edu.au",
138					},
139				]
140	},
141
142]
143
144
145monkey_icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAAZdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjbQg61aAAALIElEQVRoQ+1ZCXSU1Rm17anLaWmP1haogCiKCxWsYEApkhYr4IoiW0EW62EREBDwUIwygIhoAEGQoISwJ0B2SEIIJIRsJGQjK1lJJvvM/LPPZJZMbr/3hvmTmfmDYavn9DDnvDMDefO/e+933/d9781dd9153VHgjgK3RQHt2fky1bGXZMpgH5nq+N9lmpjJMm3iIt/bstiteKgueZmvMniETHX0b1Aeeb7LoQp5AULkG0nqk+/KbsW6N/0M7dkFvqqjo5KuBbqrv6lCx0ATN/3nI6KJmUIWGX5NxbtFLHh4kjr6rWvaSwh7WUbPkgmRr90awuTvG1K9S0JMiODhXiTUJyd6iURrQxM77cb3E4X+usGzvaHPWANz8X4Y87YTgKmSkdPEz0py+ZrI+nZpv+O+uCH/q6MnXDd4TfxsOMwKeL4s8rMQwv7pRUR9chK3CSUF8W/NB4aiKeg5t7lC+CvXZycKXZeKdKWUEPk69OoGxMbHIOT4YewO3IXs3GyRS5teDiFivBcJ+j9RqJxVfRA+/pcIG/sLJM99AE37nERo31xfFITwsW4LMVsYsjbAUhMPa10STJd2EZhX3eZYqk9g/ca12Hc4EFt3+GPNF34YPHQQcvNzRRJ2dSlUIS9KWurKd4MQ+87diJt4D05Nugenp9yL7BW9+Fz2nW7bSAgdw7KAuAgDamwuQHJKEk7GRiMm7gQsFgva2ywwZn/jXIB8WlyUjxGjnsecuTMxYdIbGOk7Av0f74vFSxe6OcpUtEeSwOUvH0XyrN/i/OweSHm/B9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DcAQBDuOALZeOktLBMGbuRf3pAGirL/GqXrRnpZvy7LmGxNWu1rn7h5euwsSu9TyjwBZwZQsWCW6LYqctRMDkaUt+CCx5R9CaexDmnCAoEjZDkRPHgWurLsGqUyJx8TCYL3wPc2aA+Ex1xJtOAtd7/yNFQoqAJupdcbGCbbORs24cGqPWozXnELeWJe8wLLmUUbKDoE3ZDiEtCEJhItSXs8ReSluVj1S/VxEz/c8wUvU1cRK7oT/7yVX1x9+8+owQv+v3vDYP9oEp9eurJH6EOnkXSnYvQOnh9RCKU1AbFwB10TkIJWlovuhUnL3MyjrYjFrYzXokr/RFKF1YnZzaE8a0b4nAThgpu6lCnNf09NvCzXnfFQ26s5S8lRNCx4FtNpeV2Lspay+aE3ZAV50P4XIm1QULtQw26GqKnGcD+ly8/3PEzujHwbNxfpkPj4AxzZ9A/8Nlne6nzO6kKFXYyzwbsX6EbuXEiLD2tzMJZgEzkTKkfYeaiA3I2foBKqN3IG/HImRtmo6Yf/URgTPwYeN+BfnxVTCcW0PPvXqop2LaHUw3NUcZ8qIv+8WF31NSvjZdzUqMAPMyVzR1MxpCVyJmWi830C7loyfej4p9C6GNfb9T3+Nz+8F3tpaYYqnx0hEQZgMz1QjuZ26LrdAkbkL+1+8Qkd6InNADp+c+jYItE6E8Ma9Ddeb5Y6P+d+A7h4/aa5mSbjHEjjH8NWjj/g1dwjLokz6DgY9PoTuzHNr4+VBHdJzF+Xd4JH1uzYa9GV+pQuiHvi5umqWqObvIYrcMhswvfn7wnYnTr5DU1frI6ATFUqFLYbLIaEoCY1kykGnj59x4f3MzKt/57h0F/o8U+C/0ys5IUjSWPgAAAABJRU5ErkJggg=="
146
147
148function find_tags(tag_name, href_pattern)
149{
150	var tags = document.getElementsByTagName(tag_name);
151	var href_tags = new Array();
152	
153	for (var i=0;i<tags.length;i++)
154	{
155		if (tags[i].href.match(href_pattern))
156		{
157			href_tags[href_tags.length] = tags[i];
158		}
159	}
160
161	return href_tags;
162}
163
164
165function rewrite_href(href_tags, snr_pattern)
166{
167	for (var i=0;i<href_tags.length;i++)
168	{		
169		/* replace old link, with new */
170		newElement = document.createElement("a");
171		node = href_tags[i].parentNode.insertBefore(newElement, href_tags[i].nextSibling);
172		node.style.textDecoration = "blink";
173		node.innerHTML = "[ Down<img style='border:0px' src=" + monkey_icon + ">Load ]";
174		node.href = href_tags[i].href;
175		node.target = "_blank";
176		href_tags[i].parentNode.removeChild(href_tags[i]);
177		
178		/* re-write href of the new link */
179		for (var j=0;j<snr_pattern.length;j++)
180		{
181			node.href = node.href.replace(snr_pattern[j].search,snr_pattern[j].replace);
182		}
183	}
184}
185
186
187for (var i=0;i<SITES.length;i++)
188{	
189	if (document.URL.match(SITES[i].url_snip)) 
190	{
191		var href_tags = find_tags(SITES[i].tag_name, SITES[i].href_pattern);
192		if ( href_tags.length > 0 )
193		{
194			rewrite_href(href_tags, SITES[i].snr_pattern);
195		}
196	}
197}
198