From a6fdbc6a4dc1b5b1b169dfce8702ad52e3a751ef Mon Sep 17 00:00:00 2001 From: fatchan Date: Tue, 11 Feb 2020 22:22:37 +1100 Subject: [PATCH] modview tweaks --- gulp/res/js/hover.js | 8 ++++---- gulp/res/js/live.js | 10 +++++----- gulp/res/js/localstorage.js | 1 + gulp/res/js/post.js | 15 ++++++++------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/gulp/res/js/hover.js b/gulp/res/js/hover.js index 31495e87..f6a1ad60 100644 --- a/gulp/res/js/hover.js +++ b/gulp/res/js/hover.js @@ -62,12 +62,12 @@ window.addEventListener('DOMContentLoaded', (event) => { const toggleHighlightPost = async function (e) { hovering = e.type === 'mouseover'; - let jsonParts = this.pathname.split('/'); + let jsonParts = this.pathname.replace(/\.html$/, '.json').split('/'); let jsonPath; - if (jsonParts[2] === 'manage') { - jsonParts.splice(2,1); - jsonPath = `${jsonParts.join('/').replace(/\.html$/, '.json')}`; + if (isModView) { + jsonParts.splice(2,1); //remove manage from json url } + jsonPath = jsonParts.join('/'); if (!this.hash) { return; //non-post number board quote } diff --git a/gulp/res/js/live.js b/gulp/res/js/live.js index 377ef75a..ae2d186e 100644 --- a/gulp/res/js/live.js +++ b/gulp/res/js/live.js @@ -30,7 +30,7 @@ window.addEventListener('settingsReady', function(event) { //after domcontentloa lastPostId = data.postId; const postData = data; //create a new post - const postHtml = post({ post: postData }); + const postHtml = post({ post: postData, modview:isModView }); //add it to the end of the thread thread.insertAdjacentHTML('beforeend', postHtml); for (let j = 0; j < postData.quotes.length; j++) { @@ -83,12 +83,12 @@ window.addEventListener('settingsReady', function(event) { //after domcontentloa window.dispatchEvent(newPostEvent); } - let jsonParts = window.location.pathname.split('/'); + let jsonParts = window.location.pathname.replace(/\.html$/, '.json').split('/'); let jsonPath; - if (jsonParts[2] === 'manage') { - jsonParts.splice(2,1); - jsonPath = `${jsonParts.join('/').replace(/\.html$/, '.json')}`; + if (isModView) { + jsonParts.splice(2,1); //remove manage from json url } + jsonPath = jsonParts.join('/'); const fetchNewPosts = async () => { console.log('fetching posts from api'); updateLive('Fetching posts...', 'yellow'); diff --git a/gulp/res/js/localstorage.js b/gulp/res/js/localstorage.js index c2099fb8..a6a94c12 100644 --- a/gulp/res/js/localstorage.js +++ b/gulp/res/js/localstorage.js @@ -1,5 +1,6 @@ const isCatalog = window.location.pathname.endsWith('catalog.html'); const isThread = /\/\w+\/thread\/\d+.html/.test(window.location.pathname); +const isModView = /\/\w+\/manage\/(thread\/)?(index|\d+).html/.test(window.location.pathname); function setLocalStorage(key, value) { try { diff --git a/gulp/res/js/post.js b/gulp/res/js/post.js index 89eb880b..ae8e6029 100644 --- a/gulp/res/js/post.js +++ b/gulp/res/js/post.js @@ -5,7 +5,7 @@ function pug_classes_object(r){var a="",n="";for(var o in r)o&&r[o]&&pug_has_own function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r]/; -function pug_style(r){if(!r)return"";if("object"==typeof r){var t="";for(var e in r)pug_has_own_property.call(r,e)&&(t=t+e+":"+r[e]+";");return t}return r+""}function post(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (Date, encodeURIComponent, ipHashSub, post) {pug_mixins["report"] = pug_interp = function(r, globalmanage=false){ +function pug_style(r){if(!r)return"";if("object"==typeof r){var t="";for(var e in r)pug_has_own_property.call(r,e)&&(t=t+e+":"+r[e]+";");return t}return r+""}function post(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;var locals_for_with = (locals || {});(function (Date, RegExp, encodeURIComponent, ipHashSub, modview, post) {pug_mixins["report"] = pug_interp = function(r, globalmanage=false){ var block = (this && this.block), attributes = (this && this.attributes) || {}; pug_html = pug_html + "\u003Cdiv class=\"reports post-container\"\u003E\u003Cinput" + (" class=\"post-check\""+" type=\"checkbox\" name=\"checkedreports\""+pug_attr("value", r.id, true, false)) + "\u002F\u003E "; if (globalmanage) { @@ -18,7 +18,7 @@ pug_html = pug_html + "\u003Ctime" + (" class=\"reltime\""+pug_attr("datetime", pug_mixins["post"] = pug_interp = function(post, truncate, manage=false, globalmanage=false, ban=false){ var block = (this && this.block), attributes = (this && this.attributes) || {}; pug_html = pug_html + "\u003Cdiv" + (" class=\"anchor\""+pug_attr("id", post.postId, true, false)) + "\u003E\u003C\u002Fdiv\u003E\u003Cdiv" + (pug_attr("class", pug_classes([`post-container ${post.thread || ban === true ? '' : 'op'}`], [true]), false, false)+pug_attr("data-board", post.board, true, false)+pug_attr("data-post-id", post.postId, true, false)+pug_attr("data-user-id", post.userId, true, false)) + "\u003E"; -const postURL = `/${post.board}/thread/${post.thread || post.postId}.html`; +const postURL = `/${post.board}/${modview ? 'manage/' : ''}thread/${post.thread || post.postId}.html`; pug_html = pug_html + "\u003Cdiv class=\"post-info\"\u003E\u003Cspan class=\"noselect\"\u003E\u003Clabel\u003E"; if (globalmanage) { pug_html = pug_html + "\u003Cinput" + (" class=\"post-check\""+" type=\"checkbox\" name=\"globalcheckedposts\""+pug_attr("value", post._id, true, false)) + "\u002F\u003E "; @@ -159,6 +159,7 @@ pug_html = pug_html + "\u003C\u002Fa\u003E\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u pug_html = pug_html + "\u003C\u002Fdiv\u003E"; } +if (post.message && modview) { post.message = post.message.replace(new RegExp(`