Skip to content

Commit

Permalink
更新样式
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaBeiyan committed Nov 25, 2024
1 parent c3b1797 commit e618f38
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 32 deletions.
17 changes: 12 additions & 5 deletions themes/mtfwiki-modified/assets/cookies-eu-banner.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@ SOFTWARE.
*/

.cookies-eu-banner-remove {
display: block;
}

.cookies-eu-banner-fixed {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
z-index:10;
}

#cookies-eu-banner {
background: #444;
color: #fff;
padding: 6px;
font-size: 13px;
text-align: center;

position: fixed;
bottom: 0;
left: 0;
width: 100%;
}
#cookies-eu-more,
#cookies-eu-accept,
Expand Down
68 changes: 41 additions & 27 deletions themes/mtfwiki-modified/assets/cookies-eu-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,26 @@ SOFTWARE.
? dnt && dnt !== "yes" && dnt !== 1 && dnt !== "1"
: true;

var isShow = null;

// Do nothing if it is a bot
// If DoNotTrack is activated, do nothing too
if (isBot || !isToTrack || this.hasConsent() === false) {
this.removeBanner(0);
return false;
isShow = false;
}

// User has already consent to use cookies to tracking
if (this.hasConsent() === true) {
if (isShow === null && this.hasConsent() === true) {
// Launch user custom function
this.launchFunction();
return true;
isShow = false;
} else {
isShow = true;
}

// If it's not a bot, no DoNotTrack and not already accept, so show banner
this.showBanner();
this.showBanner(isShow);

if (!this.waitAccept) {
// Accept cookies by default for the next page
Expand All @@ -110,7 +114,7 @@ SOFTWARE.
/*
* Show banner at the top of the page
*/
showBanner: function () {
showBanner: function (isShow) {
var _this = this,
getElementById = document.getElementById.bind(document),
banner = getElementById("cookies-eu-banner"),
Expand All @@ -125,6 +129,12 @@ SOFTWARE.
addClickListener = this.addClickListener,
removeBanner = _this.removeBanner.bind(_this, waitRemove);

banner.className = isShow
? "cookies-eu-banner-fixed"
: "cookies-eu-banner-remove";

if (rejectButton) rejectButton.style.visibility = isShow ? "visible" : "hidden";
if (acceptButton) acceptButton.style.visibility = isShow ? "visible" : "hidden";
banner.style.display = "block";

if (moreLink) {
Expand Down Expand Up @@ -195,7 +205,7 @@ SOFTWARE.
*/
hasConsent: function () {
var cookieName = this.cookieName;
if(this.useLocalStorage){
if (this.useLocalStorage) {
return this.getWithExpiry(cookieName);
}
var isCookieSetTo = function (value) {
Expand Down Expand Up @@ -254,11 +264,17 @@ SOFTWARE.
* to specify their own transition effects
*/
removeBanner: function (wait) {
var banner = document.getElementById("cookies-eu-banner");
var getElementById = document.getElementById.bind(document);
var banner = getElementById("cookies-eu-banner");
banner.classList.add("cookies-eu-banner--before-remove");
setTimeout(function () {
if (banner && banner.parentNode) {
banner.parentNode.removeChild(banner);
banner.className = "cookies-eu-banner-removed";

var rejectButton = getElementById("cookies-eu-reject");
var acceptButton = getElementById("cookies-eu-accept");
if (rejectButton) rejectButton.style.visibility = "hidden";
if (acceptButton) acceptButton.style.visibility = "hidden";
}
}, wait);
},
Expand All @@ -267,26 +283,27 @@ SOFTWARE.
return CookiesEuBanner;
});

window.document.addEventListener("DOMContentLoaded", function() {
window.document.addEventListener("DOMContentLoaded", function () {
const banner = window.document.createElement("div");
banner.id = "cookies-eu-banner";
banner.style.display = "none"; // 默认隐藏
banner.style.display = "none";

const langCode = window.location.pathname.split('/')[1].toLowerCase(); // 获取路径的第一部分
const langCode = window.location.pathname.split("/")[1].toLowerCase(); // 获取路径的第一部分
let contentText = null;
let button1=null;
let button2=null;
if(langCode==='zh-cn'){
contentText = "MtF.Wiki 的内容仅供参考,可能存在过时或不准确的信息,请谨慎甄别。"
button1='免责声明';
button2='知道了';
}
else if (langCode==='zh-hant'){
contentText = "MtF.Wiki 的內容僅供參考,可能存在過時或不準確的信息,請謹慎甄別。"
button1='免責聲明';
button2='知道了';
let button1 = null;
let button2 = null;
if (langCode === "zh-cn") {
contentText =
"MtF.Wiki 的内容仅供参考,可能存在过时或不准确的信息,请谨慎甄别。";
button1 = "免责声明";
button2 = "知道了";
} else if (langCode === "zh-hant") {
contentText =
"MtF.Wiki 的內容僅供參考,可能存在過時或不準確的信息,請謹慎甄別。";
button1 = "免責聲明";
button2 = "知道了";
}
if(contentText!=null){
if (contentText != null) {
banner.innerHTML = `
${contentText}
<a href="/zh-cn/about/disclaimer/" id="cookies-eu-more">${button1}</a>
Expand All @@ -296,9 +313,6 @@ window.document.addEventListener("DOMContentLoaded", function() {
// 将横幅添加到页面 body 的末尾
window.document.body.appendChild(banner);

new CookiesEuBanner(function() {

}, true, true);
new CookiesEuBanner(function () {}, true, true);
}

});

0 comments on commit e618f38

Please sign in to comment.