Implement a silly breadcrumb for JSON Navigation
This commit is contained in:
parent
63b0f2a9fa
commit
1d56914bcb
2
LICENSE
2
LICENSE
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.4.1 - 2014-03-03
|
* 4chan X - Version 1.4.1 - 2014-03-06
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.4.1 - 2014-03-03
|
* 4chan X - Version 1.4.1 - 2014-03-06
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
||||||
@ -12539,9 +12539,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.ready(function() {
|
$.ready(function() {
|
||||||
return $.on(window, 'popstate', Navigate.popstate);
|
$.on(window, 'popstate', Navigate.popstate);
|
||||||
|
Navigate.makeBreadCrumb(window.location, g.VIEW, g.BOARD.ID, g.THREADID);
|
||||||
|
return $.add(Index.navLinks, Navigate.el);
|
||||||
});
|
});
|
||||||
this.title = function() {};
|
this.title = function() {};
|
||||||
|
this.el = $.el('div', {
|
||||||
|
id: 'breadCrumb'
|
||||||
|
});
|
||||||
Thread.callbacks.push({
|
Thread.callbacks.push({
|
||||||
name: 'Navigate',
|
name: 'Navigate',
|
||||||
cb: this.thread
|
cb: this.thread
|
||||||
@ -12731,6 +12736,10 @@
|
|||||||
if (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0))) {
|
if (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.pathname === Navigate.path) {
|
||||||
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
$.addClass(Index.button, 'fa-spin');
|
$.addClass(Index.button, 'fa-spin');
|
||||||
if (Index.isSearching) {
|
if (Index.isSearching) {
|
||||||
Index.clearSearch();
|
Index.clearSearch();
|
||||||
@ -12745,6 +12754,12 @@
|
|||||||
Navigate.title = function() {};
|
Navigate.title = function() {};
|
||||||
delete Index.pageNum;
|
delete Index.pageNum;
|
||||||
$.rmAll(Header.hover);
|
$.rmAll(Header.hover);
|
||||||
|
if (threadID) {
|
||||||
|
view = 'thread';
|
||||||
|
} else {
|
||||||
|
pageNum = view;
|
||||||
|
view = 'index';
|
||||||
|
}
|
||||||
path = this.pathname;
|
path = this.pathname;
|
||||||
if (this.hash) {
|
if (this.hash) {
|
||||||
path += this.hash;
|
path += this.hash;
|
||||||
@ -12753,12 +12768,7 @@
|
|||||||
history.pushState(null, '', path);
|
history.pushState(null, '', path);
|
||||||
}
|
}
|
||||||
Navigate.path = this.pathname;
|
Navigate.path = this.pathname;
|
||||||
if (threadID) {
|
Navigate.makeBreadCrumb(this.href, view, boardID, threadID);
|
||||||
view = 'thread';
|
|
||||||
} else {
|
|
||||||
pageNum = view;
|
|
||||||
view = 'index';
|
|
||||||
}
|
|
||||||
_ref1 = this.dataset, indexMode = _ref1.indexMode, indexSort = _ref1.indexSort;
|
_ref1 = this.dataset, indexMode = _ref1.indexMode, indexSort = _ref1.indexSort;
|
||||||
if (indexMode && Conf['Index Mode'] !== indexMode) {
|
if (indexMode && Conf['Index Mode'] !== indexMode) {
|
||||||
$.set('Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode);
|
$.set('Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode);
|
||||||
@ -12831,6 +12841,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
makeBreadCrumb: function(href, view, boardID, threadID) {
|
||||||
|
var breadCrumb, el;
|
||||||
|
breadCrumb = $.el('span', {
|
||||||
|
className: 'crumb',
|
||||||
|
innerHTML: "<a href=" + href + ">/" + boardID + "/ - " + (view.charAt(0).toUpperCase()) + (view.slice(1)) + (threadID ? " No." + threadID : '') + "</a> > "
|
||||||
|
});
|
||||||
|
$.on(breadCrumb.firstElementChild, 'click', Navigate.navigate);
|
||||||
|
el = Navigate.el;
|
||||||
|
$.add(el, breadCrumb);
|
||||||
|
if (el.children.length > 5) {
|
||||||
|
return $.rm(el.firstChild);
|
||||||
|
}
|
||||||
|
},
|
||||||
parse: function(data) {
|
parse: function(data) {
|
||||||
var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot;
|
var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot;
|
||||||
posts = [];
|
posts = [];
|
||||||
@ -12879,9 +12902,6 @@
|
|||||||
},
|
},
|
||||||
popstate: function() {
|
popstate: function() {
|
||||||
var a;
|
var a;
|
||||||
if (window.location.pathname === Navigate.path) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
a = $.el('a', {
|
a = $.el('a', {
|
||||||
href: window.location,
|
href: window.location,
|
||||||
id: 'popState'
|
id: 'popState'
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript
|
// Generated by CoffeeScript
|
||||||
/*
|
/*
|
||||||
* 4chan X - Version 1.4.1 - 2014-03-03
|
* 4chan X - Version 1.4.1 - 2014-03-06
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
* https://github.com/Spittie/4chan-x/blob/master/LICENSE
|
||||||
@ -12553,9 +12553,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.ready(function() {
|
$.ready(function() {
|
||||||
return $.on(window, 'popstate', Navigate.popstate);
|
$.on(window, 'popstate', Navigate.popstate);
|
||||||
|
Navigate.makeBreadCrumb(window.location, g.VIEW, g.BOARD.ID, g.THREADID);
|
||||||
|
return $.add(Index.navLinks, Navigate.el);
|
||||||
});
|
});
|
||||||
this.title = function() {};
|
this.title = function() {};
|
||||||
|
this.el = $.el('div', {
|
||||||
|
id: 'breadCrumb'
|
||||||
|
});
|
||||||
Thread.callbacks.push({
|
Thread.callbacks.push({
|
||||||
name: 'Navigate',
|
name: 'Navigate',
|
||||||
cb: this.thread
|
cb: this.thread
|
||||||
@ -12745,6 +12750,10 @@
|
|||||||
if (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0))) {
|
if (e && (e.shiftKey || e.ctrlKey || (e.type === 'click' && e.button !== 0))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.pathname === Navigate.path) {
|
||||||
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
$.addClass(Index.button, 'fa-spin');
|
$.addClass(Index.button, 'fa-spin');
|
||||||
if (Index.isSearching) {
|
if (Index.isSearching) {
|
||||||
Index.clearSearch();
|
Index.clearSearch();
|
||||||
@ -12759,6 +12768,12 @@
|
|||||||
Navigate.title = function() {};
|
Navigate.title = function() {};
|
||||||
delete Index.pageNum;
|
delete Index.pageNum;
|
||||||
$.rmAll(Header.hover);
|
$.rmAll(Header.hover);
|
||||||
|
if (threadID) {
|
||||||
|
view = 'thread';
|
||||||
|
} else {
|
||||||
|
pageNum = view;
|
||||||
|
view = 'index';
|
||||||
|
}
|
||||||
path = this.pathname;
|
path = this.pathname;
|
||||||
if (this.hash) {
|
if (this.hash) {
|
||||||
path += this.hash;
|
path += this.hash;
|
||||||
@ -12767,12 +12782,7 @@
|
|||||||
history.pushState(null, '', path);
|
history.pushState(null, '', path);
|
||||||
}
|
}
|
||||||
Navigate.path = this.pathname;
|
Navigate.path = this.pathname;
|
||||||
if (threadID) {
|
Navigate.makeBreadCrumb(this.href, view, boardID, threadID);
|
||||||
view = 'thread';
|
|
||||||
} else {
|
|
||||||
pageNum = view;
|
|
||||||
view = 'index';
|
|
||||||
}
|
|
||||||
_ref1 = this.dataset, indexMode = _ref1.indexMode, indexSort = _ref1.indexSort;
|
_ref1 = this.dataset, indexMode = _ref1.indexMode, indexSort = _ref1.indexSort;
|
||||||
if (indexMode && Conf['Index Mode'] !== indexMode) {
|
if (indexMode && Conf['Index Mode'] !== indexMode) {
|
||||||
$.set('Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode);
|
$.set('Index Mode', Conf['Index Mode'] = Index.selectMode.value = indexMode);
|
||||||
@ -12845,6 +12855,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
makeBreadCrumb: function(href, view, boardID, threadID) {
|
||||||
|
var breadCrumb, el;
|
||||||
|
breadCrumb = $.el('span', {
|
||||||
|
className: 'crumb',
|
||||||
|
innerHTML: "<a href=" + href + ">/" + boardID + "/ - " + (view.charAt(0).toUpperCase()) + (view.slice(1)) + (threadID ? " No." + threadID : '') + "</a> > "
|
||||||
|
});
|
||||||
|
$.on(breadCrumb.firstElementChild, 'click', Navigate.navigate);
|
||||||
|
el = Navigate.el;
|
||||||
|
$.add(el, breadCrumb);
|
||||||
|
if (el.children.length > 5) {
|
||||||
|
return $.rm(el.firstChild);
|
||||||
|
}
|
||||||
|
},
|
||||||
parse: function(data) {
|
parse: function(data) {
|
||||||
var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot;
|
var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot;
|
||||||
posts = [];
|
posts = [];
|
||||||
@ -12893,9 +12916,6 @@
|
|||||||
},
|
},
|
||||||
popstate: function() {
|
popstate: function() {
|
||||||
var a;
|
var a;
|
||||||
if (window.location.pathname === Navigate.path) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
a = $.el('a', {
|
a = $.el('a', {
|
||||||
href: window.location,
|
href: window.location,
|
||||||
id: 'popState'
|
id: 'popState'
|
||||||
|
|||||||
@ -6,8 +6,13 @@ Navigate =
|
|||||||
$.ready ->
|
$.ready ->
|
||||||
# blink/webkit throw a popstate on page load. Not what we want.
|
# blink/webkit throw a popstate on page load. Not what we want.
|
||||||
$.on window, 'popstate', Navigate.popstate
|
$.on window, 'popstate', Navigate.popstate
|
||||||
|
Navigate.makeBreadCrumb window.location, g.VIEW, g.BOARD.ID, g.THREADID
|
||||||
|
$.add Index.navLinks, Navigate.el
|
||||||
|
|
||||||
@title = -> return
|
@title = -> return
|
||||||
|
|
||||||
|
@el = $.el 'div',
|
||||||
|
id: 'breadCrumb'
|
||||||
|
|
||||||
Thread.callbacks.push
|
Thread.callbacks.push
|
||||||
name: 'Navigate'
|
name: 'Navigate'
|
||||||
@ -155,6 +160,9 @@ Navigate =
|
|||||||
navigate: (e) ->
|
navigate: (e) ->
|
||||||
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org'
|
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org'
|
||||||
return if e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0)) # Not simply a left click
|
return if e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0)) # Not simply a left click
|
||||||
|
if @pathname is Navigate.path
|
||||||
|
e.preventDefault()
|
||||||
|
return
|
||||||
|
|
||||||
$.addClass Index.button, 'fa-spin'
|
$.addClass Index.button, 'fa-spin'
|
||||||
Index.clearSearch() if Index.isSearching
|
Index.clearSearch() if Index.isSearching
|
||||||
@ -168,17 +176,19 @@ Navigate =
|
|||||||
delete Index.pageNum
|
delete Index.pageNum
|
||||||
$.rmAll Header.hover
|
$.rmAll Header.hover
|
||||||
|
|
||||||
|
if threadID
|
||||||
|
view = 'thread'
|
||||||
|
else
|
||||||
|
pageNum = view
|
||||||
|
view = 'index' # path is "/boardID/". See the problem?
|
||||||
|
|
||||||
path = @pathname
|
path = @pathname
|
||||||
path += @hash if @hash
|
path += @hash if @hash
|
||||||
|
|
||||||
history.pushState null, '', path unless @id is 'popState'
|
history.pushState null, '', path unless @id is 'popState'
|
||||||
Navigate.path = @pathname
|
Navigate.path = @pathname
|
||||||
|
|
||||||
if threadID
|
Navigate.makeBreadCrumb @href, view, boardID, threadID
|
||||||
view = 'thread'
|
|
||||||
else
|
|
||||||
pageNum = view
|
|
||||||
view = 'index' # path is "/boardID/". See the problem?
|
|
||||||
|
|
||||||
{indexMode, indexSort} = @dataset
|
{indexMode, indexSort} = @dataset
|
||||||
if indexMode and Conf['Index Mode'] isnt indexMode
|
if indexMode and Conf['Index Mode'] isnt indexMode
|
||||||
@ -245,6 +255,17 @@ Navigate =
|
|||||||
new Notice 'error', 'Navigation Failed.', 2
|
new Notice 'error', 'Navigation Failed.', 2
|
||||||
return
|
return
|
||||||
|
|
||||||
|
makeBreadCrumb: (href, view, boardID, threadID) ->
|
||||||
|
breadCrumb = $.el 'span',
|
||||||
|
className: 'crumb'
|
||||||
|
innerHTML: "<a href=#{href}>/#{boardID}/ - #{view.charAt(0).toUpperCase()}#{view.slice 1}#{if threadID then " No.#{threadID}" else ''}</a> > "
|
||||||
|
|
||||||
|
$.on breadCrumb.firstElementChild, 'click', Navigate.navigate
|
||||||
|
|
||||||
|
{el} = Navigate
|
||||||
|
$.add el, breadCrumb
|
||||||
|
$.rm el.firstChild if el.children.length > 5
|
||||||
|
|
||||||
parse: (data) ->
|
parse: (data) ->
|
||||||
posts = []
|
posts = []
|
||||||
errors = null
|
errors = null
|
||||||
@ -287,7 +308,6 @@ Navigate =
|
|||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
|
|
||||||
popstate: ->
|
popstate: ->
|
||||||
return if window.location.pathname is Navigate.path
|
|
||||||
a = $.el 'a',
|
a = $.el 'a',
|
||||||
href: window.location
|
href: window.location
|
||||||
id: 'popState'
|
id: 'popState'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user