Avenoel Plus

Smileys exclusifs

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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;
}