Merge branch 'v3' of git://github.com/MayhemYDG/4chan-x into v3

Conflicts:
	src/features.coffee
This commit is contained in:
Zixaphir 2013-03-28 20:45:12 -07:00
commit db1c2b76b3
9 changed files with 323 additions and 256 deletions

View File

@ -15,7 +15,7 @@
// @grant GM_deleteValue
// @grant GM_openInTab
// @run-at document-start
// @updateURL https://github.com/MayhemYDG/4chan-x/raw/v3/4chan-X.meta.js
// @downloadURL https://github.com/MayhemYDG/4chan-x/raw/v3/4chan-X.user.js
// @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7
// @updateURL https://4chan-x.just-believe.in/builds/4chan-X.meta.js
// @downloadURL https://4chan-x.just-believe.in/builds/4chan-X.user.js
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC
// ==/UserScript==

File diff suppressed because one or more lines are too long

View File

@ -50,8 +50,8 @@ module.exports = (grunt) ->
process:
data: pkg
files:
'builds/<%= pkg.name %>.meta.js': 'src/metadata.js'
'builds/<%= pkg.name %>.user.js': [
'<%= pkg.name %>.meta.js': 'src/metadata.js'
'<%= pkg.name %>.user.js': [
'src/metadata.js'
'src/banner.js'
'tmp/script.js'

View File

@ -245,15 +245,17 @@ $.extend $,
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
<% if (type === 'crx') { %>
delete: (name) ->
localStorage.removeItem g.NAMESPACE + name
get: (name, defaultValue) ->
if value = localStorage.getItem g.NAMESPACE + name
JSON.parse value
delete: (keys) ->
chrome.storage.sync.remove keys
get: (key, defaultVal) ->
if val = localStorage.getItem g.NAMESPACE + key
JSON.parse val
else
defaultValue
set: (name, value) ->
localStorage.setItem g.NAMESPACE + name, JSON.stringify value
defaultVal
set: (key, val) ->
item = {}
item[key] = val
chrome.storage.sync.set item
<% } else if (type === 'userjs') { %>
do ->
# http://www.opera.com/docs/userjs/specs/#scriptstorage
@ -264,31 +266,43 @@ do ->
# To access the storage object later, keep a reference
# to the object.
{scriptStorage} = opera
$.delete = (name) ->
delete scriptStorage[g.NAMESPACE + name]
$.get = (name, defaultValue) ->
if value = scriptStorage[g.NAMESPACE + name]
JSON.parse value
$.delete = (keys) ->
unless keys instanceof Array
keys = [keys]
for key in keys
key = g.NAMESPACE + key
localStorage.removeItem key
delete scriptStorage[key]
return
$.get = (key, defaultVal) ->
if val = scriptStorage[g.NAMESPACE + key]
JSON.parse val
else
defaultValue
$.set = (name, value) ->
name = g.NAMESPACE + name
value = JSON.stringify value
defaultVal
$.set = (key, val) ->
key = g.NAMESPACE + key
val = JSON.stringify val
# for `storage` events
localStorage.setItem name, value
scriptStorage[name] = value
localStorage.setItem key, val
scriptStorage[key] = val
<% } else { %>
delete: (name) ->
GM_deleteValue g.NAMESPACE + name
get: (name, defaultValue) ->
if value = GM_getValue g.NAMESPACE + name
JSON.parse value
delete: (key) ->
unless keys instanceof Array
keys = [keys]
for key in keys
key = g.NAMESPACE + key
localStorage.removeItem key
GM_deleteValue key
return
get: (key, defaultVal) ->
if val = GM_getValue g.NAMESPACE + key
JSON.parse val
else
defaultValue
set: (name, value) ->
name = g.NAMESPACE + name
value = JSON.stringify value
defaultVal
set: (key, val) ->
key = g.NAMESPACE + key
val = JSON.stringify val
# for `storage` events
localStorage.setItem name, value
GM_setValue name, value
localStorage.setItem key, val
GM_setValue key, val
<% } %>

View File

@ -6,6 +6,7 @@
"name": "4chan X Beta",
"repo": "https://github.com/MayhemYDG/4chan-x/",
"page": "https://4chan-x.just-believe.in/",
"buildsPath": "builds/",
"mainBranch": "v3",
"matches": [
"*://api.4chan.org/*",

View File

@ -184,9 +184,10 @@ Settings =
$.asap (-> $.id 'boardNavMobile'), ->
$.prepend $.id('navtopright'), [$.tn(' ['), link, $.tn('] ')]
unless $.get 'previousversion'
if (prevVersion = $.get 'previousversion', null) isnt g.VERSION
$.set 'lastupdate', Date.now()
$.set 'previousversion', g.VERSION
$.on d, '4chanXInitFinished', Settings.open
$.on d, '4chanXInitFinished', Settings.open unless prevVersion
Settings.addSection 'Main', Settings.main
Settings.addSection 'Filter', Settings.filter
@ -304,8 +305,7 @@ Settings =
innerHTML: "<button>Hidden: #{hiddenNum}</button><span class=description>: Clear manually hidden threads and posts on /#{g.BOARD}/."
$.on $('button', div), 'click', ->
@textContent = 'Hidden: 0'
$.delete "hiddenThreads.#{g.BOARD}"
$.delete "hiddenPosts.#{g.BOARD}"
$.delete ["hiddenThreads.#{g.BOARD}", "hiddenPosts.#{g.BOARD}"]
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div
export: ->
now = Date.now()
@ -3555,7 +3555,6 @@ Unread =
Unread.lastReadPost = $.get("lastReadPosts.#{@board}", threads: {}).threads[@] or 0
Unread.posts = []
Unread.postsQuotingYou = []
Unread.titleEl = $ 'title', d.head
Unread.title = d.title
posts = []
for ID, post of @posts
@ -3637,17 +3636,10 @@ Unread =
count = Unread.posts.length
if Conf['Unread Count']
prefix = if count
"(#{count})"
d.title = if g.DEAD
"(#{Unread.posts.length}) /#{g.BOARD}/ - 404"
else
''
# XXX Chrome bug where it doesn't always update the tab title.
# crbug.com/16650
# crbug.com/124381
Unread.titleEl.textContent = if g.DEAD
"#{prefix} /#{g.BOARD}/ - 404"
else
"#{prefix} #{Unread.title}"
"(#{Unread.posts.length}) #{Unread.title}"
return unless Conf['Unread Tab Icon']
@ -3667,10 +3659,12 @@ Unread =
else
Favicon.default
<% if (type !== 'crx') { %>
# `favicon.href = href` doesn't work on Firefox.
# `favicon.href = href` isn't enough on Opera.
# Opera won't always update the favicon if the href didn't change.
$.add d.head, Favicon.el
<% } %>
Favicon =
init: ->

View File

@ -463,6 +463,7 @@ Main =
Main.callbackNodes Post, posts
$.event '4chanXInitFinished'
Main.checkUpdate()
callbackNodes: (klass, nodes) ->
# get the nodes' length only once
@ -486,13 +487,39 @@ Main =
obj = e.detail
unless typeof obj.callback.name is 'string'
throw new Error "Invalid callback name: #{obj.callback.name}"
Klass = if obj.type is 'Post'
Post
else
Thread
switch obj.type
when 'Post'
Klass = Post
when 'Thread'
Klass = Thread
else
return
obj.callback.isAddon = true
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 or $.get('lastchecked', 0) > 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) ->
unless 'length' of errors
error = errors

View File

@ -14,6 +14,8 @@
"run_at": "document_start"
}],
"homepage_url": "<%= meta.page %>",
"incognito": "spanning",
"minimum_chrome_version": "25"
"minimum_chrome_version": "25",
"permissions": [
"storage"
]
}

View File

@ -16,7 +16,7 @@
// @grant GM_deleteValue
// @grant GM_openInTab
// @run-at document-start
// @updateURL <%= meta.page %>builds/<%= name %>.meta.js
// @downloadURL <%= meta.page %>builds/<%= name %>.user.js
// @updateURL <%= meta.page %><%= meta.buildsPath %><%= name %>.meta.js
// @downloadURL <%= meta.page %><%= meta.buildsPath %><%= name %>.user.js
// @icon data:image/png;base64,<%= grunt.file.read('img/icon48.png', {encoding: 'base64'}) %>
// ==/UserScript==