From 43fd3e8956aa2672ac16387ac62e043f3c1dfd58 Mon Sep 17 00:00:00 2001 From: kilo Date: Sun, 17 Sep 2017 22:10:43 +0200 Subject: [PATCH] Sync JS cookies & Go cookies's domain & random other things (#1571) * create JS domain variable * use domain JS variable when creating cookies * Create getDomainName() function in Go * Update template_functions_test.go * Update template_functions_test.go * recreate cookie when resetCookies() is called * Update main.css * Update classic.css * show "unknown" instead of "0 0 0" if stats are unknown * don't show top ad if there's an announcement * remove BBCode support that broke description's line breaks * remove useless identifier * hide error instead of fixing it * Update markdown_test.go * Update markdown_test.go * css for tags in classic * remove wrong explanation for alternating color * fix RSS URL in header * remove eu cookie
from base * fix cookie warning never showing up * Update main.js * nyaa.se-like styling for upload form on classic.css * Smaller markdown toolbar on classic upload form * Fix indent, non-round borders for markdown & language list on classic * Update view.jet.html * add fillZero function * ditto but in test * Update view.jet.html * add RJ prefix to dlsite link * Update template_functions_test.go * Update listing.jet.html * prevent responsiveness of upload form in classic.css * remove now useless css rule * fix tag input padding on classic * Update template_functions_test.go * rollback workaround * rollback workaround * rollback workaround * remove now unused function * ditto * Update main.css --- public/css/classic.css | 61 +++++++++++++++++++- public/css/main.css | 24 +++++++- public/js/main.js | 42 +++++++++----- templates/layouts/partials/base.jet.html | 7 +-- templates/site/torrents/listing.jet.html | 7 ++- templates/site/torrents/view.jet.html | 2 +- templates/site/user/public/settings.jet.html | 1 - templates/template_functions.go | 9 +++ templates/template_functions_test.go | 16 +++++ 9 files changed, 142 insertions(+), 27 deletions(-) diff --git a/public/css/classic.css b/public/css/classic.css index e3c1fd4e..e3915a6f 100644 --- a/public/css/classic.css +++ b/public/css/classic.css @@ -55,7 +55,7 @@ a:hover { } #content { - top: 32px!important; + top: 31px!important; } .tr-cat { @@ -579,3 +579,62 @@ a.nav-btn.log-in { min-height: 22px; padding: 1px 0; } + +span.tag { + border-radius: 0; + box-shadow: none; + border: 1px solid #c5c5c5; +} + + +.upload-form-table { + width: auto; +} +.upload-form-table .table-input-label label::after { + content: ':'; +} + +.upload-form-table .table-input-label { + width: 136px!important; + display: table-cell!important; +} + +.upload-form-table input, .upload-form-table select, .upload-form-table textarea, .upload-form-table div { + max-width: 406px!important; +} +.upload-form-table .table-torrent-link input { + width: 100%!important; +} +.upload-form-table .editor-toolbar { + padding: 0 2px; + font-size: 10px; +} +.upload-form-table .editor-toolbar, .upload-form-table .CodeMirror { + border-radius: 0; + border-color: #c4c4c4; + opacity: 1; +} +.upload-form-table .editor-toolbar::before { + margin-bottom: 2px; +} +.upload-form-table .editor-toolbar::after { + margin-top: 4px; +} +.upload-form-table .editor-toolbar a { + width: 26px; + height: 24px; +} +.upload-form-table .editor-toolbar a:before { + line-height: 25px; +} +.upload-form-table .CodeMirror-scroll, .upload-form-table .CodeMirror { + min-height: 120px; +} + +.form-input.language { + border-radius: 0; + padding: 7px 3px; +} +.upload-tag-table td { + padding-right: 5px!important; +} diff --git a/public/css/main.css b/public/css/main.css index f8a39149..c93a25cf 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -34,6 +34,7 @@ img[class^="jl-"], img[class^="wb-"] { img[class$="-w"] { max-height: 90px; padding: 0 2px; + margin-bottom: 1px; } .center.bottom { margin: 0 auto; @@ -338,7 +339,7 @@ select.form-input { #content { position: relative; - top: 57px; + top: 53px; } #content.content-admin { top: 108px!important; @@ -1963,6 +1964,27 @@ p.upload-rules { margin: 10px 0; } +.upload-tag-form .form-group { + width: 167px; + display:inline-block; + margin-bottom: 5px; + margin-right: 5px; +} + +.upload-tag-form label { + display:inline-block; + width: 100%; + font-size: unset; + margin-bottom: 1px; +} + +.upload-tag-form input,.upload-tag-form select { + height: 25px; + padding: 3px 3px; + width: 100%; +} + + .show-xs { display: none; } diff --git a/public/js/main.js b/public/js/main.js index 151a4950..9bd92042 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -92,17 +92,26 @@ function resetCookies() { //Remove all cookies but exclude those in the above array for (var i = 0; i < cookies.length; i++) { var cookieName = (cookies[i].split("=")[0]).trim() - //Remove spaces because some cookie names have it - if (excludedCookies.includes(cookieName)) continue + //Trim spaces because some cookie names have them at times + if (excludedCookies.includes(cookieName)) { + if(domain == "pantsu.cat") { + //only execute if cookie are supposed to be shared between nyaa & sukebei + var cookieValue = getCookieValue(cookieName) + document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;" + document.cookie = cookieName + "=" + cookieValue + ";expires=" + farFutureString + ";domain=" + domain + //Remove cookie and re-create it to ensure domain is correct + } + continue + } document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;" } //Set new version in cookie - document.cookie = "commit=" + commitVersion + ";expires=" + farFutureString + document.cookie = "commit=" + commitVersion + ";expires=" + farFutureString + ";domain=" + domain var oneHour = new Date() oneHour.setTime(oneHour.getTime() + 1 * 3600 * 1500) - document.cookie = "newVersion=true; expires=" + oneHour.toUTCString() + document.cookie = "newVersion=true; expires=" + oneHour.toUTCString() + ";domain=" + domain } @@ -128,9 +137,7 @@ function startupCode() { if (!document.cookie.includes("commit")) resetCookies() else { - var startPos = document.cookie.indexOf("commit") + 7, - endPos = document.cookie.substring(startPos).indexOf(";"), - userCommitVersion = endPos == "-1" ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos); + var userCommitVersion = getCookieValue("commit"); //Get start and end position of Commit string, need to start searching endPos from version cookie in case it's not the first cookie in the string //If endPos is equal to -1, aka if the version cookie is at the very end of the string and doesn't have an ";", the endPos is not used @@ -151,9 +158,7 @@ function startupCode() { document.getElementById("dark-toggle").addEventListener("click", toggleTheme); if(document.cookie.includes("theme=")) { - var startPos = document.cookie.indexOf("theme=") + 6 - var endPos = document.cookie.substring(startPos).indexOf(";") - UserTheme = [endPos == "-1" ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos), "tomorrow"] + UserTheme = [getCookieValue("theme"), "tomorrow"] //Get user's default theme and set the alternative one as tomorrow } else @@ -162,9 +167,7 @@ function startupCode() { if(document.cookie.includes("theme2=")) { - var startPos = document.cookie.indexOf("theme2=") + 7 - var endPos = document.cookie.substring(startPos).indexOf(";") - UserTheme[1] = endPos == "-1" ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos) + UserTheme[1] = getCookieValue("theme2") //If user already has ran the ToggleTheme() function in the past, we get the value of the second theme (the one the script switches to) if(!UserTheme.includes("tomorrow")) UserTheme[1] = "tomorrow" @@ -177,7 +180,7 @@ function startupCode() { if(UserTheme[0] == UserTheme[1]) UserTheme[1] = "g" //If tomorrow is twice in UserTheme, which happens when the user already has tomorrow as his default theme and toggle the dark mode for the first time, we set the second theme as g.css - document.cookie = "theme2=" + UserTheme[1] + ";path=/;domain=pantsu.cat;expires=" + farFutureString + document.cookie = "theme2=" + UserTheme[1] + ";path=/;expires=" + farFutureString + ";domain=" + domain //Set cookie for future theme2 uses } @@ -195,8 +198,8 @@ function toggleTheme(e) { //If user logged in, we're forced to go through this page in order to save the new user theme } else { - document.cookie = "theme=" + CurrentTheme + ";path=/;domain=pantsu.cat;expires=" + farFutureString - document.cookie = "theme2=" + (CurrentTheme == UserTheme[0] ? UserTheme[1] : UserTheme[0]) + ";path=/;domain=pantsu.cat;expires=" + farFutureString + document.cookie = "theme=" + CurrentTheme + ";path=/;expires=" + farFutureString + ";domain=" + domain + document.cookie = "theme2=" + (CurrentTheme == UserTheme[0] ? UserTheme[1] : UserTheme[0]) + ";path=/;expires=" + farFutureString + ";domain=" + domain //Otherwise, we can just set the theme through cookies } @@ -234,4 +237,11 @@ function humanFileSize(bytes, si) { var i = ~~(Math.log(bytes) / Math.log(k)) return i == 0 ? bytes + " B" : (bytes / Math.pow(k, i)).toFixed(1) + " " + "KMGTPEZY" [i - 1] + (si ? "" : "i") + "B" } + +function getCookieValue(cookieName) { + var startPos = document.cookie.indexOf(cookieName + "=") + cookieName.length + 1 + var endPos = document.cookie.substring(startPos).indexOf(";") + return endPos == "-1" ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos) +} + // @license-end diff --git a/templates/layouts/partials/base.jet.html b/templates/layouts/partials/base.jet.html index 680c460b..0571f744 100644 --- a/templates/layouts/partials/base.jet.html +++ b/templates/layouts/partials/base.jet.html @@ -22,7 +22,7 @@ - + @@ -54,7 +54,7 @@
{{ yield infos()}} {{ yield errors()}} -
{{ yield ad_wide(Type=AdType, ID=AdID) }}
+ {{ if !isset(Infos["system"])}}
{{ yield ad_wide(Type=AdType, ID=AdID) }}
{{end}} {{ block content_body_base() }}{{end}}
{{ block mascot() }} @@ -97,8 +97,7 @@
- {{ if !EUCookieLaw && URL.String() == ""}}{{ end }} - + {{block footer_js()}}{{end}} diff --git a/templates/site/torrents/listing.jet.html b/templates/site/torrents/listing.jet.html index 984fc4d9..88c06162 100644 --- a/templates/site/torrents/listing.jet.html +++ b/templates/site/torrents/listing.jet.html @@ -3,11 +3,11 @@ {{block title()}}{{ T("home")}}{{end}} {{block contclass()}}{{if User.HasAdmin() }}content-admin{{end}}{{end}} {{block content_body()}} -{{ if OldNav }} +{{ if OldNav || Theme == "classic"}} {{ include "layouts/partials/helpers/oldNav" }} {{ end }} -
+
@@ -94,7 +94,7 @@ - {{if .LastScrape.IsZero}} + {{if .LastScrape.IsZero || formatDateRFC(.LastScrape) == "0001-01-01T00:00:00Z"}} {{else}} @@ -138,6 +138,7 @@ +{{ if !EUCookieLaw }}{{ end }}
{{ fileSize(.Filesize, T) }} {{ T("unknown")}}{{.Seeders}}