Forum cleaner

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-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Forum cleaner
// @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.40
// @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 = 'Forum cleaner';
  Forenputze.version = '1.40';
  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.mainPage = 'index.php';
  Forenputze.read = 'Gelesen markieren';
  Forenputze.gameLogin = 'Login im Spiel';
  Forenputze.login = 'Login';
  Forenputze.registration = 'Registrieren';
  Forenputze.conversations = 'Unterhaltungen';
  Forenputze.settings = 'Grundeinstellungen';
  Forenputze.logout = 'Logout';
  Forenputze.registrationLink = 'https://www.the-west.de/?page=create_forum_account';
  Forenputze.scrollUp = 'Nach oben springen';
  Forenputze.goToLastPost = 'Zum letzten Beitrag gehen';
  Forenputze.askUpdate = 'Für das Benutzerskript "' + Forenputze.name + '" ist eine neuere Version verfügbar. Soll sie installiert werden?';
  //************************************
  //************************************
  //Language
  //************************************
  //************************************
  //Main function, runs the other functions
  Forenputze.run = function () {
    Forenputze.checkUpdate();
    Forenputze.changeHomeLinks();
    Forenputze.addLinks();
    Forenputze.formatLogo();
    Forenputze.addPageUp();
    Forenputze.changeReadIconColor();
    Forenputze.highlightLastPost();
    Forenputze.addLastPostButton();
    Forenputze.changeDesign();
    Forenputze.addForumReadButton();
  };
  //************************************
  //************************************
  //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.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 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.login + '</a></li>'));
      ownMenu.append($('<li><a target="_blank" href="' + Forenputze.registrationLink + '" class="primaryContent"><i style="padding-right:7px;" class="fa fa-user fa-lg fa-fw"></i>' + Forenputze.registration + '</a></li>'));
      $('.quickLinksBar').append(ownMenu);
      return;
    } //When cookie set, add game login link

    if (getCookie('ig_conv_last_site') != '') {
      var gameLogin = $('<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.gameLogin + '</a>');
      $('.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.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.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.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
    $(document).ready(function () {
      var container = $('.breadBoxBottom').find('fieldset.breadcrumb');
      var pageUpButton = $('<a title="' + Forenputze.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');
      //Add click listener      
      pageUpButton.click(function () {
        window.scrollTo(0, 0);
      });
      if (container.find('.sidebarCollapse.icon-hdr_strong').exists()) {
        container.find('.sidebarCollapse.icon-hdr_strong').after(pageUpButton);
      } else {
        container.find('.OverlayTrigger.jumpMenuTrigger').after(pageUpButton);
      }
    });
  };
  //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.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.goToLastPost + '" href="' + link + '" class="fa fa-arrow-right fa-lg fa-fw"></a>'));
    });
  };
  //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');
  };
  //Checks whether the user is logged (true) in or not (false)
  isLoggedIn = function () {
    return $('li#adm_right.navTab.login').size() < 1;
  };
  //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 '';
  };
  //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);
});