Notify users of available updates. #968
This commit is contained in:
parent
60737bd33e
commit
57d65aa22a
@ -6,6 +6,7 @@
|
|||||||
"name": "4chan X Beta",
|
"name": "4chan X Beta",
|
||||||
"repo": "https://github.com/MayhemYDG/4chan-x/",
|
"repo": "https://github.com/MayhemYDG/4chan-x/",
|
||||||
"page": "https://4chan-x.just-believe.in/",
|
"page": "https://4chan-x.just-believe.in/",
|
||||||
|
"buildsPath": "builds/",
|
||||||
"mainBranch": "v3",
|
"mainBranch": "v3",
|
||||||
"matches": [
|
"matches": [
|
||||||
"*://api.4chan.org/*",
|
"*://api.4chan.org/*",
|
||||||
|
|||||||
@ -210,9 +210,10 @@ Settings =
|
|||||||
order: 110
|
order: 110
|
||||||
open: -> Conf['Enable 4chan\'s Extension']
|
open: -> Conf['Enable 4chan\'s Extension']
|
||||||
|
|
||||||
unless $.get 'previousversion'
|
if (prevVersion = $.get 'previousversion', null) isnt g.VERSION
|
||||||
|
$.set 'lastupdate', Date.now()
|
||||||
$.set 'previousversion', g.VERSION
|
$.set 'previousversion', g.VERSION
|
||||||
$.on d, '4chanXInitFinished', Settings.open
|
$.on d, '4chanXInitFinished', Settings.open unless prevVersion
|
||||||
|
|
||||||
Settings.addSection 'Main', Settings.main
|
Settings.addSection 'Main', Settings.main
|
||||||
Settings.addSection 'Filter', Settings.filter
|
Settings.addSection 'Filter', Settings.filter
|
||||||
|
|||||||
@ -457,6 +457,7 @@ Main =
|
|||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
|
|
||||||
$.event '4chanXInitFinished'
|
$.event '4chanXInitFinished'
|
||||||
|
Main.checkUpdate()
|
||||||
|
|
||||||
callbackNodes: (klass, nodes) ->
|
callbackNodes: (klass, nodes) ->
|
||||||
# get the nodes' length only once
|
# get the nodes' length only once
|
||||||
@ -480,13 +481,39 @@ Main =
|
|||||||
obj = e.detail
|
obj = e.detail
|
||||||
unless typeof obj.callback.name is 'string'
|
unless typeof obj.callback.name is 'string'
|
||||||
throw new Error "Invalid callback name: #{obj.callback.name}"
|
throw new Error "Invalid callback name: #{obj.callback.name}"
|
||||||
Klass = if obj.type is 'Post'
|
switch obj.type
|
||||||
Post
|
when 'Post'
|
||||||
else
|
Klass = Post
|
||||||
Thread
|
when 'Thread'
|
||||||
|
Klass = Thread
|
||||||
|
else
|
||||||
|
return
|
||||||
obj.callback.isAddon = true
|
obj.callback.isAddon = true
|
||||||
Klass::callbacks.push obj.callback
|
Klass::callbacks.push obj.callback
|
||||||
|
|
||||||
|
checkUpdate: ->
|
||||||
|
return unless Main.isThisPageLegit()
|
||||||
|
# Check for updates after:
|
||||||
|
# - 6 hours since the last update on Opera because it lacks auto-updating.
|
||||||
|
# - 7 days since the last update on Chrome/Firefox.
|
||||||
|
# After that, check for updates every day if we still haven't updated.
|
||||||
|
now = Date.now()
|
||||||
|
freq = <% if (type === 'userjs') { %>6 * $.HOUR<% } else { %>7 * $.DAY<% } %>
|
||||||
|
if $.get('lastupdate', 0) > now - freq and $.get('lastchecked') > now - $.DAY
|
||||||
|
return
|
||||||
|
$.ajax '<%= meta.page %><%= meta.buildsPath %>version', onload: ->
|
||||||
|
return unless @status is 200
|
||||||
|
version = @response
|
||||||
|
return unless /^\d\.\d+\.\d+$/.test version
|
||||||
|
if g.VERSION is version
|
||||||
|
# Don't check for updates too frequently if there wasn't one in a 'long' time.
|
||||||
|
$.set 'lastupdate', now
|
||||||
|
return
|
||||||
|
$.set 'lastchecked', now
|
||||||
|
el = $.el 'span',
|
||||||
|
innerHTML: "Update: <%= meta.name %> v#{version} is out, get it <a href=<%= meta.page %> target=_blank>here</a>."
|
||||||
|
new Notification 'info', el, 2 * $.MINUTE
|
||||||
|
|
||||||
handleErrors: (errors) ->
|
handleErrors: (errors) ->
|
||||||
unless 'length' of errors
|
unless 'length' of errors
|
||||||
error = errors
|
error = errors
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
// @grant GM_deleteValue
|
// @grant GM_deleteValue
|
||||||
// @grant GM_openInTab
|
// @grant GM_openInTab
|
||||||
// @run-at document-start
|
// @run-at document-start
|
||||||
// @updateURL <%= meta.page %>builds/<%= name %>.meta.js
|
// @updateURL <%= meta.page %><%= meta.buildsPath %><%= name %>.meta.js
|
||||||
// @downloadURL <%= meta.page %>builds/<%= name %>.user.js
|
// @downloadURL <%= meta.page %><%= meta.buildsPath %><%= name %>.user.js
|
||||||
// @icon data:image/png;base64,<%= grunt.file.read('img/icon48.png', {encoding: 'base64'}) %>
|
// @icon data:image/png;base64,<%= grunt.file.read('img/icon48.png', {encoding: 'base64'}) %>
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user