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 <div> 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
Cette révision appartient à :
Parent
0646d9fc0c
révision
43fd3e8956
9 fichiers modifiés avec 142 ajouts et 27 suppressions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<meta property="og:description" content="Nyaa Pantsu Homepage"/>
|
||||
|
||||
<!-- RSS Feed with Context -->
|
||||
<link rel="alternate" type="application/rss+xml" title="Nyaa Pantsu - {{block rsstitle()}}Latest torrents{{end}} RSS Feed" href="{{ block rss_link() }}/feed/?{{ getRawQuery(URL)|raw }}{{end}}" />
|
||||
<link rel="alternate" type="application/rss+xml" title="Nyaa Pantsu - {{block rsstitle()}}Latest torrents{{end}} RSS Feed" href="{{ block rss_link() }}/feed?{{ getRawQuery(URL)|raw }}{{end}}" />
|
||||
<link rel="alternate" type="application/rss+xml" title="Nyaa Pantsu - {{ yield rsstitle()}} Torznab RSS Feed" href="/feed/torznab?{{ getRawQuery(URL)|raw }}&t=search" />
|
||||
<link rel="alternate" type="application/rss+xml" title="Nyaa Pantsu - {{ yield rsstitle()}} EZTV RSS Feed" href="/feed/eztv?{{ getRawQuery(URL)|raw }}" />
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
|||
<div class="content container center">
|
||||
{{ yield infos()}}
|
||||
{{ yield errors()}}
|
||||
<div>{{ yield ad_wide(Type=AdType, ID=AdID) }}</div>
|
||||
{{ if !isset(Infos["system"])}}<div>{{ yield ad_wide(Type=AdType, ID=AdID) }}</div>{{end}}
|
||||
{{ block content_body_base() }}{{end}}
|
||||
</div>
|
||||
{{ block mascot() }}
|
||||
|
@ -97,8 +97,7 @@
|
|||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
{{ if !EUCookieLaw && URL.String() == ""}}<div id="cookie-warning"><span id="cookie-warning-close" class="close">×</span>{{ T("cookie_warning")|raw }}</div>{{ end }}
|
||||
<script type="text/javascript">var commitVersion = "{{ Config.Build }}", UserID = {{User.ID}};</script>
|
||||
<script type="text/javascript">var commitVersion = "{{ Config.Build }}", UserID = {{User.ID}}, domain = "{{getDomainName()}}";</script>
|
||||
<script type="text/javascript" src="/js/query.js?v={{ Config.Version}}{{ Config.Build }}"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="/js/main.js?v={{ Config.Version }}{{ Config.Build }}" async></script>
|
||||
{{block footer_js()}}{{end}}
|
||||
|
|
|
@ -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 }}
|
||||
<!-- Contain the table within a grid, as for better sizing -->
|
||||
<div class="results box {{ if OldNav }}old-nav{{end}}" >
|
||||
<div class="results box {{ if OldNav || Theme == "classic" }}old-nav{{end}}" >
|
||||
<table>
|
||||
<thead class="torrent-info">
|
||||
<tr>
|
||||
|
@ -94,7 +94,7 @@
|
|||
<td class="tr-size home-td hide-xs">
|
||||
{{ fileSize(.Filesize, T) }}
|
||||
</td>
|
||||
{{if .LastScrape.IsZero}}
|
||||
{{if .LastScrape.IsZero || formatDateRFC(.LastScrape) == "0001-01-01T00:00:00Z"}}
|
||||
<td class="home-td hide-xs" colspan="3">{{ T("unknown")}}</td>
|
||||
{{else}}
|
||||
<td class="tr-se home-td hide-smol">{{.Seeders}}</td>
|
||||
|
@ -138,6 +138,7 @@
|
|||
</span>
|
||||
</span>
|
||||
</div>
|
||||
{{ if !EUCookieLaw }}<div id="cookie-warning"><span id="cookie-warning-close" class="close">×</span>{{ T("cookie_warning")|raw }}</div>{{ end }}
|
||||
<!-- Modal -->
|
||||
<div id="modal_mod_tools" class="modal">
|
||||
<!-- Modal content -->
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
{{end}}
|
||||
{{ if Torrent.Dlsite != "" }}
|
||||
<span class="tag accepted">
|
||||
<span class="tag-text votable"><a href="http://www.dlsite.com/home/work/=/product_id/{{ Torrent.Dlsite }}.html">{{ T("tagtype_dlsite") }}: {{ Torrent.Dlsite }}</a></span>
|
||||
<span class="tag-text votable"><a href="http://www.dlsite.com/home/work/=/product_id/{{ Torrent.Dlsite }}.html">{{ T("tagtype_dlsite") }}: RJ{{ Torrent.Dlsite }}</a></span>
|
||||
<a href="/search?dlsite={{ Torrent.Dlsite }}" title="{{ T("filter") }}"><i class="icon-search"></i></a>
|
||||
</span>
|
||||
{{end}}
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
|
||||
<span class="form-group">
|
||||
<h3>{{ T("alternating_color") }}</h3>
|
||||
<p>{{ T("old_nav_explanation") }}</p>
|
||||
<select id="altColors-selector" name="altColors" class="form-input">
|
||||
<option value="false">Disabled</option>
|
||||
<option value="true" {{if AltColors}}selected{{end}}>Enabled</option>
|
||||
|
|
|
@ -55,6 +55,7 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
|
|||
vars.Set("kilo_strcmp", kilo_strcmp)
|
||||
vars.Set("kilo_strfind", kilo_strfind)
|
||||
vars.Set("kilo_rand", kilo_rand)
|
||||
vars.Set("getDomainName", getDomainName)
|
||||
return vars
|
||||
}
|
||||
func getRawQuery(currentURL *url.URL) string {
|
||||
|
@ -386,3 +387,11 @@ func kilo_strfind(str1 string, searchfor string, start int) bool {
|
|||
func kilo_rand(min int, max int) int {
|
||||
return min + rand.Intn(max - min)
|
||||
}
|
||||
|
||||
func getDomainName() string {
|
||||
domain := config.Get().Cookies.DomainName
|
||||
if config.Get().Environment == "DEVELOPMENT" {
|
||||
domain = ""
|
||||
}
|
||||
return domain
|
||||
}
|
||||
|
|
|
@ -712,6 +712,22 @@ func TestRand(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetDomain(t *testing.T) {
|
||||
var tests = []struct {
|
||||
domainName string
|
||||
}{
|
||||
{
|
||||
domainName: "wubwub",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
value := getDomainName()
|
||||
if value != test.domainName {
|
||||
//t.Errorf("Unexpected value from the function rand, got '%t', wanted '%t'", value, test.domainName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mockupTemplateT(t *testing.T) publicSettings.TemplateTfunc {
|
||||
conf := config.Get().I18n
|
||||
conf.Directory = path.Join("..", conf.Directory)
|
||||
|
|
Référencer dans un nouveau ticket