diff --git a/couchpotato/core/plugins/userscript/main.py b/couchpotato/core/plugins/userscript/main.py index 34ab6b50..569f36de 100644 --- a/couchpotato/core/plugins/userscript/main.py +++ b/couchpotato/core/plugins/userscript/main.py @@ -5,8 +5,10 @@ from couchpotato.core.helpers.request import getParam, jsonified from couchpotato.core.helpers.variable import isDict from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin +from couchpotato.environment import Env from flask.globals import request -from flask.helpers import url_for, make_response +from flask.helpers import url_for +import os log = CPLog(__name__) @@ -14,13 +16,13 @@ log = CPLog(__name__) class Userscript(Plugin): def __init__(self): - addApiView('userscript.get', self.getExtension) + addApiView('userscript.get/', self.getUserScript, static = True) addApiView('userscript', self.iFrame) addApiView('userscript.add_via_url', self.getViaUrl) addEvent('userscript.get_version', self.getVersion) - def getExtension(self): + def getUserScript(self, filename = ''): params = { 'includes': fireEvent('userscript.get_includes', merge = True), @@ -30,10 +32,11 @@ class Userscript(Plugin): 'host': request.host_url, } - response = make_response(self.renderTemplate(__file__, 'template.js', **params)) - response.headers['Content-Type'] = 'text/javascript' - return response - return + script = self.renderTemplate(__file__, 'template.js', **params) + self.createFile(os.path.join(Env.get('cache_dir'), 'couchpotato.user.js'), script) + + from flask.helpers import send_from_directory + return send_from_directory(Env.get('cache_dir'), 'couchpotato.user.js') def getVersion(self): diff --git a/couchpotato/core/plugins/userscript/static/userscript.js b/couchpotato/core/plugins/userscript/static/userscript.js index c17bc2c4..01451aaa 100644 --- a/couchpotato/core/plugins/userscript/static/userscript.js +++ b/couchpotato/core/plugins/userscript/static/userscript.js @@ -85,7 +85,7 @@ var UserscriptSettingTab = new Class({ }).inject(self.content).adopt( new Element('a', { 'text': 'Install userscript', - 'href': Api.createUrl('userscript.get')+'?couchpotato.user.js', + 'href': Api.createUrl('userscript.get')+'couchpotato.user.js', 'normalhref': true }) ); diff --git a/couchpotato/core/plugins/userscript/template.js b/couchpotato/core/plugins/userscript/template.js index 6244afb5..64839fb7 100644 --- a/couchpotato/core/plugins/userscript/template.js +++ b/couchpotato/core/plugins/userscript/template.js @@ -13,7 +13,7 @@ // ==/UserScript== var version = {{version}}, - host = '{{host}}'; + host = '{{host}}', api = '{{api}}'; function create() {