Add word boundaries to the style switcher regex
This commit is contained in:
parent
8ddf2b4e5f
commit
7d4825dce0
@ -12226,15 +12226,15 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Navigate.updateTitle(board);
|
Navigate.updateTitle(board);
|
||||||
return Navigate.updateFavicon(!!board.ws_board);
|
return Navigate.updateSFW(!!board.ws_board);
|
||||||
};
|
};
|
||||||
return req = $.ajax('//a.4cdn.org/boards.json', {
|
return req = $.ajax('//a.4cdn.org/boards.json', {
|
||||||
onabort: onload,
|
onabort: onload,
|
||||||
onloadend: onload
|
onloadend: onload
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateFavicon: function(sfw) {
|
updateSFW: function(sfw) {
|
||||||
var findStyle, mainStyleSheet, newStyleSheet, style;
|
var findStyle, style;
|
||||||
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
|
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
|
||||||
$.add(d.head, Favicon.el);
|
$.add(d.head, Favicon.el);
|
||||||
if (Favicon.SFW === sfw) {
|
if (Favicon.SFW === sfw) {
|
||||||
@ -12244,14 +12244,12 @@
|
|||||||
Favicon.update();
|
Favicon.update();
|
||||||
findStyle = function(type, base) {
|
findStyle = function(type, base) {
|
||||||
var style;
|
var style;
|
||||||
style = d.cookie.match(new RegExp("" + type + "\_style\=([^;]+)"));
|
style = d.cookie.match(new RegExp("\b" + type + "\_style\=([^;]+);\b"));
|
||||||
return ["" + type + "_style", (style ? style[1] : base)];
|
return ["" + type + "_style", (style ? style[1] : base)];
|
||||||
};
|
};
|
||||||
style = findStyle.apply(null, sfw ? ['ws', 'Yotsuba B New'] : ['nws', 'Yotsuba New']);
|
style = findStyle.apply(null, (sfw ? ['ws', 'Yotsuba B New'] : ['nws', 'Yotsuba New']));
|
||||||
$.globalEval("var style_group = '" + style[0] + "'");
|
$.globalEval("var style_group = '" + style[0] + "'");
|
||||||
mainStyleSheet = $('link[title=switch]', d.head);
|
$('link[title=switch]', d.head).href = $("link[title='" + style[1] + "']", d.head).href;
|
||||||
newStyleSheet = $("link[title='" + style[1] + "']", d.head);
|
|
||||||
mainStyleSheet.href = newStyleSheet.href;
|
|
||||||
return Main.setClass();
|
return Main.setClass();
|
||||||
},
|
},
|
||||||
updateTitle: function(_arg) {
|
updateTitle: function(_arg) {
|
||||||
@ -12316,7 +12314,7 @@
|
|||||||
if (view === 'index') {
|
if (view === 'index') {
|
||||||
return Index.update(pageNum);
|
return Index.update(pageNum);
|
||||||
} else {
|
} else {
|
||||||
Navigate.updateFavicon(Favicon.SFW);
|
Navigate.updateSFW(Favicon.SFW);
|
||||||
load = Navigate.load;
|
load = Navigate.load;
|
||||||
Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", {
|
Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", {
|
||||||
onabort: load,
|
onabort: load,
|
||||||
|
|||||||
@ -12145,11 +12145,19 @@
|
|||||||
return QR.generatePostableThreadsList();
|
return QR.generatePostableThreadsList();
|
||||||
},
|
},
|
||||||
updateContext: function(view) {
|
updateContext: function(view) {
|
||||||
|
var oldView;
|
||||||
|
if (view === g.VIEW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$.rmClass(doc, g.VIEW);
|
$.rmClass(doc, g.VIEW);
|
||||||
$.addClass(doc, view);
|
$.addClass(doc, view);
|
||||||
|
oldView = g.VIEW;
|
||||||
g.VIEW = view;
|
g.VIEW = view;
|
||||||
return {
|
return {
|
||||||
index: function() {
|
index: function() {
|
||||||
|
if (oldView === g.VIEW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
delete g.THREADID;
|
delete g.THREADID;
|
||||||
QR.link.textContent = 'Start a Thread';
|
QR.link.textContent = 'Start a Thread';
|
||||||
$.off(d, 'ThreadUpdate', QR.statusCheck);
|
$.off(d, 'ThreadUpdate', QR.statusCheck);
|
||||||
@ -12157,6 +12165,9 @@
|
|||||||
},
|
},
|
||||||
thread: function() {
|
thread: function() {
|
||||||
g.THREADID = +window.location.pathname.split('/')[3];
|
g.THREADID = +window.location.pathname.split('/')[3];
|
||||||
|
if (oldView === g.VIEW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QR.link.textContent = 'Reply to Thread';
|
QR.link.textContent = 'Reply to Thread';
|
||||||
$.on(d, 'ThreadUpdate', QR.statusCheck);
|
$.on(d, 'ThreadUpdate', QR.statusCheck);
|
||||||
return $.off(d, 'IndexRefresh', QR.generatePostableThreadsList);
|
return $.off(d, 'IndexRefresh', QR.generatePostableThreadsList);
|
||||||
@ -12204,15 +12215,15 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Navigate.updateTitle(board);
|
Navigate.updateTitle(board);
|
||||||
return Navigate.updateFavicon(!!board.ws_board);
|
return Navigate.updateSFW(!!board.ws_board);
|
||||||
};
|
};
|
||||||
return req = $.ajax('//a.4cdn.org/boards.json', {
|
return req = $.ajax('//a.4cdn.org/boards.json', {
|
||||||
onabort: onload,
|
onabort: onload,
|
||||||
onloadend: onload
|
onloadend: onload
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateFavicon: function(sfw) {
|
updateSFW: function(sfw) {
|
||||||
var findStyle, mainStyleSheet, newStyleSheet, style;
|
var findStyle, style;
|
||||||
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
|
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
|
||||||
$.add(d.head, Favicon.el);
|
$.add(d.head, Favicon.el);
|
||||||
if (Favicon.SFW === sfw) {
|
if (Favicon.SFW === sfw) {
|
||||||
@ -12222,14 +12233,12 @@
|
|||||||
Favicon.update();
|
Favicon.update();
|
||||||
findStyle = function(type, base) {
|
findStyle = function(type, base) {
|
||||||
var style;
|
var style;
|
||||||
style = d.cookie.match(new RegExp("" + type + "\_style\=([^;]+)"));
|
style = d.cookie.match(new RegExp("\b" + type + "\_style\=([^;]+);\b"));
|
||||||
return ["" + type + "_style", (style ? style[1] : base)];
|
return ["" + type + "_style", (style ? style[1] : base)];
|
||||||
};
|
};
|
||||||
style = findStyle.apply(null, sfw ? ['ws', 'Yotsuba B New'] : ['nws', 'Yotsuba New']);
|
style = findStyle.apply(null, (sfw ? ['ws', 'Yotsuba B New'] : ['nws', 'Yotsuba New']));
|
||||||
$.globalEval("var style_group = '" + style[0] + "'");
|
$.globalEval("var style_group = '" + style[0] + "'");
|
||||||
mainStyleSheet = $('link[title=switch]', d.head);
|
$('link[title=switch]', d.head).href = $("link[title='" + style[1] + "']", d.head).href;
|
||||||
newStyleSheet = $("link[title='" + style[1] + "']", d.head);
|
|
||||||
mainStyleSheet.href = newStyleSheet.href;
|
|
||||||
return Main.setClass();
|
return Main.setClass();
|
||||||
},
|
},
|
||||||
updateTitle: function(_arg) {
|
updateTitle: function(_arg) {
|
||||||
@ -12273,26 +12282,28 @@
|
|||||||
pageNum = view;
|
pageNum = view;
|
||||||
view = 'index';
|
view = 'index';
|
||||||
}
|
}
|
||||||
if (view !== g.VIEW) {
|
Navigate.updateContext(view);
|
||||||
|
if (!(view === g.VIEW && boardID === g.BOARD.ID)) {
|
||||||
Navigate.disconnect();
|
Navigate.disconnect();
|
||||||
Navigate.clean();
|
Navigate.clean();
|
||||||
Navigate.updateContext(view);
|
|
||||||
Navigate.reconnect();
|
Navigate.reconnect();
|
||||||
}
|
}
|
||||||
if (view === 'index') {
|
if (boardID === g.BOARD.ID) {
|
||||||
if (boardID === g.BOARD.ID) {
|
Navigate.title = function() {
|
||||||
Navigate.title = function() {
|
if (view === 'index') {
|
||||||
return d.title = $('.boardTitle').textContent;
|
return d.title = $('.boardTitle').textContent;
|
||||||
};
|
}
|
||||||
} else {
|
};
|
||||||
g.BOARD = new Board(boardID);
|
} else {
|
||||||
Navigate.title = function() {
|
g.BOARD = new Board(boardID);
|
||||||
return Navigate.updateBoard(boardID);
|
Navigate.title = function() {
|
||||||
};
|
return Navigate.updateBoard(boardID);
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
if (view === 'index') {
|
||||||
return Index.update(pageNum);
|
return Index.update(pageNum);
|
||||||
} else {
|
} else {
|
||||||
Navigate.updateFavicon(Favicon.SFW);
|
Navigate.updateSFW(Favicon.SFW);
|
||||||
load = Navigate.load;
|
load = Navigate.load;
|
||||||
Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", {
|
Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", {
|
||||||
onabort: load,
|
onabort: load,
|
||||||
@ -12319,6 +12330,7 @@
|
|||||||
new Notice('warning', "Failed to load thread." + (req.status ? " " + req.status : ''));
|
new Notice('warning', "Failed to load thread." + (req.status ? " " + req.status : ''));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Navigate.title();
|
||||||
try {
|
try {
|
||||||
return Navigate.parse(JSON.parse(req.response).posts);
|
return Navigate.parse(JSON.parse(req.response).posts);
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
|
|||||||
@ -142,13 +142,13 @@ Navigate =
|
|||||||
|
|
||||||
return unless board
|
return unless board
|
||||||
Navigate.updateTitle board
|
Navigate.updateTitle board
|
||||||
Navigate.updateFavicon !!board.ws_board
|
Navigate.updateSFW !!board.ws_board
|
||||||
|
|
||||||
req = $.ajax '//a.4cdn.org/boards.json',
|
req = $.ajax '//a.4cdn.org/boards.json',
|
||||||
onabort: onload
|
onabort: onload
|
||||||
onloadend: onload
|
onloadend: onload
|
||||||
|
|
||||||
updateFavicon: (sfw) ->
|
updateSFW: (sfw) ->
|
||||||
# TODO: think of a better name for this. Changes style, too.
|
# TODO: think of a better name for this. Changes style, too.
|
||||||
Favicon.el.href = "//s.4cdn.org/image/favicon#{if sfw then '-ws' else ''}.ico"
|
Favicon.el.href = "//s.4cdn.org/image/favicon#{if sfw then '-ws' else ''}.ico"
|
||||||
$.add d.head, Favicon.el # Changing the href alone doesn't update the icon on Firefox
|
$.add d.head, Favicon.el # Changing the href alone doesn't update the icon on Firefox
|
||||||
@ -158,20 +158,17 @@ Navigate =
|
|||||||
Favicon.SFW = sfw
|
Favicon.SFW = sfw
|
||||||
Favicon.update()
|
Favicon.update()
|
||||||
findStyle = (type, base) ->
|
findStyle = (type, base) ->
|
||||||
style = d.cookie.match new RegExp "#{type}\_style\=([^;]+)"
|
style = d.cookie.match new RegExp "\b#{type}\_style\=([^;]+);\b"
|
||||||
return ["#{type}_style", (if style then style[1] else base)]
|
return ["#{type}_style", (if style then style[1] else base)]
|
||||||
|
|
||||||
style = findStyle.apply null, if sfw
|
style = findStyle (if sfw
|
||||||
['ws', 'Yotsuba B New']
|
['ws', 'Yotsuba B New']
|
||||||
else
|
else
|
||||||
['nws', 'Yotsuba New']
|
['nws', 'Yotsuba New'])...
|
||||||
|
|
||||||
$.globalEval "var style_group = '#{style[0]}'"
|
$.globalEval "var style_group = '#{style[0]}'"
|
||||||
|
|
||||||
mainStyleSheet = $ 'link[title=switch]', d.head
|
$('link[title=switch]', d.head).href = $("link[title='#{style[1]}']", d.head).href
|
||||||
newStyleSheet = $ "link[title='#{style[1]}']", d.head
|
|
||||||
|
|
||||||
mainStyleSheet.href = newStyleSheet.href
|
|
||||||
|
|
||||||
Main.setClass()
|
Main.setClass()
|
||||||
|
|
||||||
@ -225,7 +222,7 @@ Navigate =
|
|||||||
|
|
||||||
# Moving from index to thread or thread to thread
|
# Moving from index to thread or thread to thread
|
||||||
else
|
else
|
||||||
Navigate.updateFavicon Favicon.SFW
|
Navigate.updateSFW Favicon.SFW
|
||||||
{load} = Navigate
|
{load} = Navigate
|
||||||
Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json",
|
Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json",
|
||||||
onabort: load
|
onabort: load
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user