Forenputze

Applies changes to the user interface of The-West's XenForo forum including design changes, addition of useful links like "Forum read"-buttons and other features.

当前为 2016-08-28 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Forenputze
// @description Applies changes to the user interface of The-West's XenForo forum including design changes, addition of useful links like "Forum read"-buttons and other features.
// @namespace fktext.bplaced.net/forenputze
// @include http*://forum.the-west.*/*
// @include http*://forum.beta.the-west.*/*
// @version 1.44
// @grant none
// @author stayawayknight
// ==/UserScript==
//Add new JS source
function contentEval(source) {
  if ('function' == typeof source) {
    source = '(' + source + ')();';
  }
  var script = document.createElement('script');
  script.setAttribute('type', 'application/javascript');
  script.textContent = source;
  document.body.appendChild(script);
  document.body.removeChild(script);
}
Forenputze = function () {
  Forenputze = {
    initialized: false
  };
  //************************************
  //General settings
  Forenputze.name = 'Forenputze';
  Forenputze.version = '1.44';
  Forenputze.lang = 'net';
  Forenputze.updateURL = 'https://greasyfork.org/scripts/22679-forenputze/code/Forenputze.user.js';
  Forenputze.updateCheckURL = 'https://greasyfork.org/de/scripts/22679-forenputze';
  Forenputze.updateStorageKey = 'forenputze_last_check';
  Forenputze.checkUpdateIntervall = 60 * 60 * 1000;
  Forenputze.collapseCookieExpireDays = 365;
  Forenputze.collapseCookieName = 'xf_express';
  Forenputze.mainPage = 'index.php';
  //************************************
  //************************************
  //Language
  Forenputze.langs = {
    de: {
      read: 'Gelesen markieren',
      gameLogin: 'Login im Spiel',
      login: 'Login',
      registration: 'Registrieren',
      conversations: 'Unterhaltungen',
      settings: 'Grundeinstellungen',
      logout: 'Logout',
      scrollUp: 'Nach oben springen',
      goToLastPost: 'Zum letzten Beitrag gehen',
      registered: 'Registriert',
      askUpdate: 'Für das Benutzerskript "' + Forenputze.name + '" ist eine neuere Version verfügbar. Soll sie installiert werden?'
    },
    net: {
      read: 'Mark as read',
      gameLogin: 'Login into the game',
      login: 'Login',
      registration: 'Register',
      conversations: 'Conversations',
      settings: 'Basic settings',
      logout: 'Logout',
      scrollUp: 'Back to top',
      goToLastPost: 'Go to last post',
      registered: 'Registered',
      askUpdate: 'A new version of the userscript "' + Forenputze.name + '" is available. Do you want to install it?'
    },
    pl: {
      read: 'Oznacz jako przeczytane',
      gameLogin: 'Zaloguj się do gry',
      login: 'Zaloguj się',
      registration: 'Rejestracja',
      conversations: 'Prywatne wiadomości',
      settings: 'Podstawowe ustawienia',
      logout: 'Wyloguj się',
      scrollUp: 'Powrót do góry',
      goToLastPost: 'Idź do ostatniego postu',
      registered: 'Zarejestrowany',
      askUpdate: 'Nowa wersja skryptu "' + Forenputze.name + '" jest dostępna. Czy chcesz go zaktualizować?'
    }
  };
  //************************************
  //************************************
  //Main function, runs the other functions
  Forenputze.run = function () {
    Forenputze.resolveLang();
    Forenputze.checkUpdate();
    Forenputze.changeHomeLinks();
    Forenputze.addLinks();
    Forenputze.formatLogo();
    Forenputze.addPageUp();
    Forenputze.removeShareSection();
    Forenputze.changeReadIconColor();
    Forenputze.highlightLastPost();
    Forenputze.addLastPostButton();
    Forenputze.addForumReadButton();
    Forenputze.setCollapseCookieTime();
    Forenputze.formatPosts();
    Forenputze.changeDesign();
  };
  //************************************
  //************************************
  Forenputze.resolveLang = function () {
    var tld = getTLD();
    if (Forenputze.langs[tld]) {
      Forenputze.lang = tld;
    }
  };
  //Update check
  Forenputze.checkUpdate = function () {
    //Check whether it is time for an update check or not (to avoid long loading times)
    if (localStorage.getItem(Forenputze.updateStorageKey)) {
      var lastTime = localStorage.getItem(Forenputze.updateStorageKey);
      var curTime = Date.now() + '';
      //Compare
      if ((curTime - lastTime) < Forenputze.checkUpdateIntervall) {
        //No update check necessary
        return;
      }
    } //Update last check time in local storage

    localStorage.setItem(Forenputze.updateStorageKey, Date.now() + '');
    $.get(Forenputze.updateCheckURL, function (data, textStatus, jqxhr) {
      //Check for success
      if ((jqxhr.status != 200) || (textStatus != 'success')) {
        console.log('Forenputze: Cannot check for update; Status: ' + jqxhr.status);
        return;
      }
      var versionContainer = $(data).find('dd.script-show-version').find('span');
      //Version on remote server found?
      if (!versionContainer.exists()) {
        console.log('Forenputze: Cannot get remote version.')
        return;
      } //Get remote version from container

      var versionRemote = versionContainer.text();
      //Compare remote and own version
      if (versionRemote > Forenputze.version) {
        //Update possible
        var choice = confirm(Forenputze.langs[Forenputze.lang].askUpdate);
        //Perform update
        if (choice) {
          window.location = Forenputze.updateURL;
        }
      }
    });
  };
  //************************************
  //Functions to adjust the forum ui
  //Change links that lead to TW to forum links
  Forenputze.changeHomeLinks = function () {
    //Logo:
    $('#logo').find('a').attr('href', Forenputze.mainPage);
    //Home:
    $('.homeCrumb').find('a').attr('href', Forenputze.mainPage);
    //Navigation:
    $('.navTab.home.PopupClosed').find('a').attr('href', Forenputze.mainPage);
  };
  //Adds a logout button to the Quick link list
  Forenputze.addLinks = function () {
    //Check whether logged in
    if (!isLoggedIn()) {
      //Extend menu for guests
      var registerLink = $('#adm_right2.navTab.login').find('a').attr('href');
      var ownMenu = $('<ul></ul>');
      ownMenu.append($('<li><a href="index.php?login" class="primaryContent OverlayTrigger"><i style="padding-right:7px;" class="fa fa-sign-in fa-lg fa-fw"></i>' + Forenputze.langs[Forenputze.lang].login + '</a></li>'));
      ownMenu.append($('<li><a target="_blank" href="' + registerLink + '" class="primaryContent"><i style="padding-right:7px;" class="fa fa-user fa-lg fa-fw"></i>' + Forenputze.langs[Forenputze.lang].registration + '</a></li>'));
      $('.quickLinksBar').append(ownMenu);
      return;
    } //When cookie set, add game login link

    if (getCookie('ig_conv_last_site') != '') {
      var gameLogin = $('<li><a class="primaryContent" target="_blank" href="' + getCookie('ig_conv_last_site') + '"><i class="fa fa-gamepad fa-lg fa-fw" style="padding-right:7px;"></i>' + Forenputze.langs[Forenputze.lang].gameLogin + '</a><li>');
      $('.quickLinksBar').find('.section').find('ul').prepend(gameLogin);
    } //Extend menu for users

    var ownMenu = $('<ul></ul>');
    ownMenu.append($('<li><a href="index.php?conversations" class="primaryContent"><i style="padding-right:7px;" class="fa fa-inbox fa-lg fa-fw"></i>' + Forenputze.langs[Forenputze.lang].conversations + '</a></li>'));
    ownMenu.append($('<li><a href="index.php?account/preferences" class="primaryContent"><i style="padding-right:7px;" class="fa fa-cog fa-lg fa-fw"></i>' + Forenputze.langs[Forenputze.lang].settings + '</a></li>'));
    ownMenu.append($('<li><a href="index.php?logout" class="primaryContent OverlayTrigger"><i style="padding-right:7px;" class="fa fa-sign-out fa-lg fa-fw"></i>' + Forenputze.langs[Forenputze.lang].logout + '</a></li>'));
    $('.quickLinksBar').append(ownMenu);
  };
  //Resize main logo
  Forenputze.formatLogo = function () {
    $('#header').css('background', 'rgba(0,0,0,0) url("styles/west_mx/xenforo/headbg.png") no-repeat scroll center top');
    $('#header').css('background-size', '100%');
    $('#header').css('height', '250px');
    $('#headerProxy').css('height', '255px');
  };
  //Add a page up button to the lower bar of the page
  Forenputze.addPageUp = function () {
    //Wait till everything is loaded
    var container = $('.breadBoxBottom').find('fieldset.breadcrumb');
    var pageUpButton = $('<a title="' + Forenputze.langs[Forenputze.lang].scrollUp + '" class="fa fa-arrow-up fa-lg fa-fw"></a>');
    //Set CSS properties
    pageUpButton.css('cursor', 'pointer');
    pageUpButton.css('color', '#371902');
    pageUpButton.css('display', 'block');
    pageUpButton.css('float', 'right');
    pageUpButton.css('font-size', '18px');
    pageUpButton.css('height', '24px');
    pageUpButton.css('line-height', '24px');
    pageUpButton.css('margin-right', '5px');
    //Add class for recognition
    pageUpButton.addClass('page-up-button');
    //Add click listener      
    pageUpButton.click(function () {
      window.scrollTo(0, 0);
    });
    if (container.find('.sidebarCollapse').exists()) {
      container.find('.sidebarCollapse').after(pageUpButton);
    } else {
      container.find('.OverlayTrigger.jumpMenuTrigger').after(pageUpButton);
    }
  };
  //Removes the share section above each thread
  Forenputze.removeShareSection = function () {
    $('.sharePage').remove();
  };
  //Saturate the non-read forum icons to create a bigger difference betweeen read and unread elements
  Forenputze.changeReadIconColor = function () {
    var icons = $('.nodeInfo').not('.unread, .linkNodeInfo').find('span.nodeIcon');
    //Usual:
    icons.css('filter', 'saturate(20%)');
    //Chrome, Opera, Safari:
    icons.css('-webkit-filter', 'saturate(20%)');
  };
  //Make the "Latest" text bold
  Forenputze.highlightLastPost = function () {
    $('.lastThreadTitle').find('span').css('font-weight', 'bold');
  };
  //Add a "mark read" button to each forum
  Forenputze.addForumReadButton = function () {
    //Check whehther logged in
    if (!isLoggedIn()) {
      return;
    }
    $('.nodeInfo.forumNodeInfo.primaryContent.unread').each(function (i, obj) {
      //Get link and add mark-read option
      var link = $(this).find('.nodeTitle').find('a').attr('href');
      link += '-/mark-read';
      //Add link near topic
      $(this).find('.nodeTitle').append('&nbsp;').append($('<a class="OverlayTrigger" style="font-size: 10px;" href="' + link + '">[' + Forenputze.langs[Forenputze.lang].read + ']</a>'));
      //Add link to forum icon
      $(this).find('span.nodeIcon').wrap($('<a class="OverlayTrigger" href="' + link + '"></a>'));
    });
  };
  //Add a "go to last post" button to each thread in the overview
  Forenputze.addLastPostButton = function () {
    $('.discussionListItem').each(function (index, obj) {
      //Get latest post link
      var link = $(this).find('.listBlock.lastPost').find('.muted').find('a').attr('href');
      if ((typeof link === 'undefined') || !isLoggedIn()) {
        return;
      } //Add button

      $(this).find('.title').append('&nbsp;').append($('<a title="' + Forenputze.langs[Forenputze.lang].goToLastPost + '" href="' + link + '" class="fa fa-arrow-right fa-lg fa-fw"></a>'));
    });
  };
  //Adds onclick listeners to the category collapse buttons that ensure that the remembering cookie lasts one year and do not expire with the session
  Forenputze.setCollapseCookieTime = function () {
    //Function for persisting the cookie
    persist = function () {
      setCookie(Forenputze.collapseCookieName, getCookie(Forenputze.collapseCookieName), Forenputze.collapseCookieExpireDays);
    };
    //Add onclick listeners to persist the cookie always when a category is clicked
    $('.CatTrigger').click(function () {
      persist();
    });
    //Persist cookie for the first time
    if (getCookie(Forenputze.collapseCookieName) && getCookie(Forenputze.collapseCookieName) != '') {
      persist();
    }
  };
  //Formats the posts so that they become smaller
  Forenputze.formatPosts = function () {
    //Replace long usernames with ellipsis
    $('.username').each(function () {
      $(this).attr('title', $(this).text());
      $(this).css('text-overflow', 'ellipsis').css('white-space', 'nowrap');
    });
    //Increase the width of user profile section every post a little bit
    $('.messageUserInfo').css('padding-left', '5px').css('width', '160px');
    //Removes the "agreement" section in user profiles in posts
    var userInfo = $('.extraUserInfo');
    userInfo.each(function () {
      $(this).find('.pairsJustified').eq(0).find('dt').text(Forenputze.langs[Forenputze.lang].registered + ':');
      $(this).find('.pairsJustified').eq(2).remove();
    });
    //Format the pairs in the user vocabulary for better readability
    var pairs = userInfo.find('.pairsJustified');
    pairs.css('font-size', '12px');
    pairs.find('dt').css('font-weight', 100).css('text-transform', 'none');
    pairs.find('dd').css('text-transform', 'none');
  };
  //Do same changes to the design, including a change of the background
  Forenputze.changeDesign = function () {
    //Wooden background
    $('body').css('background-image', 'url(https://westdes.innogamescdn.com/images/interface/wood_texture_dark.jpg)');
    //Remove footer color
    $('footer').find('.footer').find('.pageContent').css('background-color', 'rgba(0, 0, 0, 0.0)');
    //Wooden moderator bar
    $('#moderatorBar').css('background-image', 'url(https://westdes.innogamescdn.com/images/interface/wood_texture_dark.jpg)');
    //Moderator items color
    $('.modLink').css('background-color', '#ffeecc');
    //Searchbar
    $('<style>#searchBar::after{color: #ffeecc</style>').appendTo('head');
    //Forum content texture
    $('#content').find('.pageContent').css('background-image', 'url(https://westdes.innogamescdn.com/images/window/forum/external_bg.jpg)');
    //Rounded corners
    $('#content').find('.pageContent').css('border-radius', '10px');
    //Message background
    $('<style>.message{background-image: url(https://westdes.innogamescdn.com/images/tw2gui/groupframe/groupframe_bg.jpg)</style>').appendTo('head');
    //Rounded corners in message user block
    $('.messageUserBlock ').css('border-radius', '20px');
    //Let buttons look like west buttons
    $('<style>.button:not(.bbCodeSpoilerButton){background-color: rgba(0,0,0,0) !important; border: 0px solid #371902; color: #ffe7b1 !important; background-size: 100% 100%; background-image: url(https://westdes.innogamescdn.com/images/tw2gui/button/button_normal.png?1)}</style>').appendTo('head');
    //Change breadcrumb bars to western bars
    var breadcrumbs = $('.breadcrumb');
    breadcrumbs.css('background-image', 'url("https://westdes.innogamescdn.com/images/tw2gui/window/window2_title.png?13")');
    breadcrumbs.css('background-size', '100% 100%');
    breadcrumbs.css('background-color', 'rgba(0,0,0,0)');
    breadcrumbs.css('box-shadow', 'none');
    breadcrumbs.css('border-radius', '0px');
    breadcrumbs.css('padding-left', '15px');
    breadcrumbs.css('padding-right', '15px');
    //Change color of the text and arrow of the bar
    var crumbs = $('.crumb, .sidebarCollapse, .icon-room, .page-up-button');
    crumbs.css('color', '#ffeecc');
    crumbs.css('background-color', 'rgba(0,0,0,0)');
    crumbs.css('border-bottom', 'none');
    $('<style>.breadcrumb .crust .arrow::before{color: #ffeecc}</style>').appendTo('head');
  };
  //Checks whether the user is logged (true) in or not (false)
  isLoggedIn = function () {
    return $('li#adm_right.navTab.login').size() < 1;
  };
  //Returns the top level domain of the current site
  getTLD = function () {
    var tld = window.location.hostname;
    tld = tld.split('.');
    pos = tld.length - 1;
    return tld[pos];
  };
  //Reads a cookie
  getCookie = function (c_name) {
    if (document.cookie.length > 0) {
      c_start = document.cookie.indexOf(c_name + '=');
      if (c_start != - 1) {
        c_start = c_start + c_name.length + 1;
        c_end = document.cookie.indexOf(';', c_start);
        if (c_end == - 1) {
          c_end = document.cookie.length;
        }
        return unescape(document.cookie.substring(c_start, c_end));
      }
    }
    return '';
  };
  //Sets a cookie with name, value and days
  setCookie = function (name, value, days) {
    var expires;
    if (days) {
      var date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
      expires = '; expires=' + date.toUTCString();
    } 
    else {
      expires = '';
    }
    document.cookie = name + '=' + value + expires + '; path=/';
  };
  //Query extension to check whether a exception is empty or not
  $.fn.exists = function () {
    return this.length !== 0;
  };
  //Run main function
  Forenputze.run();
  //Let XenForo crawl the overlays
  $('body').xfActivate();
};
$(document).ready(function () {
  contentEval(Forenputze);
});