Avenoel Plus

Smileys exclusifs

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Avenoel Plus
// @version      0.2
// @description  Smileys exclusifs
// @author       Xehanort
// @include      http://avenoel.org/*
// @exclude      http://avenoel.org/blabla.php*
// @namespace https://greasyfork.org/users/14292
// ==/UserScript==

var version = 0.2;
var smileys = [];

function escapeRegExp(str) {
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

function updateSmileys() {
  for (var i in smileys) {
    var re = new RegExp(escapeRegExp(smileys[i].code), "g");
    if (document.location.pathname == "/chat.php") {
      var messages = document.querySelectorAll('.amessage');
      for (var j = 0; j < messages.length; j++) {
        messages[j].innerHTML =  messages[j].innerHTML.replace(re, '<img src="'+smileys[i].link+'" />')
      }
    } else {
      document.body.innerHTML = document.body.innerHTML.replace(re, '<img src="'+smileys[i].link+'" />');
    }
  }
}

function ajax(url, callback) {
  var xhr = new XMLHttpRequest();

  xhr.onreadystatechange = function() {
    if (xhr.readyState==4 && xhr.status==200) {
      callback(xhr);
    }
  }

  xhr.open("GET", url, false);
  xhr.send(null);
}

function update(xhr) {
  if (version < xhr.responseText) alert("Avenoel Plus doit être mis à jour");
}

ajax("http://xehanort.alwaysdata.net/AvenoelPlus/version.php", update);
ajax("http://xehanort.alwaysdata.net/AvenoelPlus/smileys.php", function(xhr) {
  smileys = eval(xhr.responseText);
});

updateSmileys();

if (document.location.pathname == "/chat.php") {
  console.log(document.querySelector('.messages'))
  document.querySelector(".messages").onscroll = updateSmileys;
}