Prevent userscript from caching when updating

This commit is contained in:
Ruud committed 2012-04-07 14:24:47 +02:00
1 parent d0796ee423
commit 6199c0385c
2 files changed
+5 -6

No files matched your search

+2 -3
View File
@@ -1,4 +1,3 @@
from couchpotato import index
from couchpotato.api import addApiView from couchpotato.api import addApiView
from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.event import fireEvent, addEvent
from couchpotato.core.helpers.request import getParam, jsonified from couchpotato.core.helpers.request import getParam, jsonified
@@ -19,7 +18,7 @@ class Userscript(Plugin):
version = 2 version = 2
def __init__(self): def __init__(self):
addApiView('userscript.get/<path:filename>', self.getUserScript, static = True) addApiView('userscript.get/<random>/<path:filename>', self.getUserScript, static = True)
addApiView('userscript', self.iFrame) addApiView('userscript', self.iFrame)
addApiView('userscript.add_via_url', self.getViaUrl) addApiView('userscript.add_via_url', self.getViaUrl)
addApiView('userscript.bookmark', self.bookmark) addApiView('userscript.bookmark', self.bookmark)
@@ -36,7 +35,7 @@ class Userscript(Plugin):
return self.renderTemplate(__file__, 'bookmark.js', **params) return self.renderTemplate(__file__, 'bookmark.js', **params)
def getUserScript(self, filename = ''): def getUserScript(self, random = '', filename = ''):
params = { params = {
'includes': fireEvent('userscript.get_includes', merge = True), 'includes': fireEvent('userscript.get_includes', merge = True),
@@ -82,7 +82,7 @@ var UserscriptSettingTab = new Class({
}).inject(self.settings.tabs.automation.content, 'top').adopt( }).inject(self.settings.tabs.automation.content, 'top').adopt(
(userscript ? [new Element('a.userscript.button', { (userscript ? [new Element('a.userscript.button', {
'text': 'Install userscript', 'text': 'Install userscript',
'href': Api.createUrl('userscript.get')+'couchpotato.user.js', 'href': Api.createUrl('userscript.get')+randomString()+'/couchpotato.user.js',
'target': '_self' 'target': '_self'
}), new Element('span.or[text=or]')] : null), }), new Element('span.or[text=or]')] : null),
new Element('span.bookmarklet').adopt( new Element('span.bookmarklet').adopt(
@@ -90,7 +90,7 @@ var UserscriptSettingTab = new Class({
'text': '+CouchPotato', 'text': '+CouchPotato',
'href': "javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','" + 'href': "javascript:void((function(){var e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','" +
host_url + Api.createUrl('userscript.bookmark') + host_url + Api.createUrl('userscript.bookmark') +
"?host="+ encodeURI(host_url + Api.createUrl('userscript.get')) + "?host="+ encodeURI(host_url + Api.createUrl('userscript.get')+randomString()+'/') +
"&r='+Math.random()*99999999);document.body.appendChild(e)})());", "&r='+Math.random()*99999999);document.body.appendChild(e)})());",
'target': '', 'target': '',
'events': { 'events': {
@@ -126,7 +126,7 @@ window.addEvent('load', function(){
if(your_version && your_version < latest_version && checked_already < latest_version){ if(your_version && your_version < latest_version && checked_already < latest_version){
if(confirm("Update to the latest Userscript?\nYour version: " + your_version + ', new version: ' + latest_version )){ if(confirm("Update to the latest Userscript?\nYour version: " + your_version + ', new version: ' + latest_version )){
document.location = Api.getOption('url')+'userscript.get/couchpotato.user.js'; document.location = Api.createUrl('userscript.get')+randomString()+'/couchpotato.user.js';
} }
Cookie.write(key, latest_version, {duration: 100}); Cookie.write(key, latest_version, {duration: 100});
} }