diff --git a/couchpotato/core/plugins/userscript/main.py b/couchpotato/core/plugins/userscript/main.py index 569f36de..ae3447aa 100644 --- a/couchpotato/core/plugins/userscript/main.py +++ b/couchpotato/core/plugins/userscript/main.py @@ -15,6 +15,8 @@ log = CPLog(__name__) class Userscript(Plugin): + version = 1 + def __init__(self): addApiView('userscript.get/', self.getUserScript, static = True) addApiView('userscript', self.iFrame) @@ -42,7 +44,7 @@ class Userscript(Plugin): versions = fireEvent('userscript.get_provider_version') - version = 0 + version = self.version for v in versions: version += v diff --git a/couchpotato/core/plugins/userscript/template.js b/couchpotato/core/plugins/userscript/template.js index 69cb42e0..e2e9b85e 100644 --- a/couchpotato/core/plugins/userscript/template.js +++ b/couchpotato/core/plugins/userscript/template.js @@ -1,7 +1,7 @@ // ==UserScript== // @name CouchPotato UserScript // @description Add movies like a real CouchPotato -// @version {{version}} +// @version {{version}} // @match {{host}}* {% for include in includes %} @@ -72,8 +72,12 @@ var close_img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8 var osd = function(){ var navbar, newElement; + var createApiUrl = function(url){ + return host + api + "?url=" + escape(url) + }; + var iframe = create('iframe', { - 'src': host + api + "?url=" + escape(document.location.href), + 'src': createApiUrl(document.location.href), 'frameborder': 0, 'scrolling': 'no' }); @@ -85,6 +89,16 @@ var osd = function(){ 'innerHTML': '', 'id': 'add_to', 'onclick': function(){ + + // Try and get imdb url + try { + var regex = new RegExp(/tt(\d+)/); + var imdb_id = document.body.innerHTML.match(regex)[0]; + if (imdb_id) + iframe.setAttribute('src', createApiUrl('http://imdb.com/title/'+imdb_id+'/')) + } + catch(e){} + popup.innerHTML = ''; popup.appendChild(create('a', { 'innerHTML': '', @@ -103,10 +117,10 @@ var osd = function(){ }; var setVersion = function(){ - document.body.setAttribute('data-userscript_version', version) + document.body.setAttribute('data-userscript_version', version) }; if(document.location.href.indexOf(host) == -1) - osd(); + osd(); else - setVersion(); \ No newline at end of file + setVersion(); \ No newline at end of file