NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Sauvegarde Messages 2s // @namespace http://tampermonkey.net/ // @version 0.1 // @description Evitez de perdre vos messages sur 2S // @author Wesker // @include /https?://2sucres.org/*/ // @licence MIT // @grant none // ==/UserScript== (function() { 'use strict'; var message_input = document.getElementById('message_input') var mutation_number = 0 function createCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires="+d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } function clear_message(){ if(readCookie('message_2s') != null){ eraseCookie('message_2s') } } function edit_message(){ if(readCookie('message_2s') != null){ message_input.value = readCookie('message_2s') } message_input.addEventListener('keydown', function(){ var a = createCookie('message_2s', message_input.value, 400); }) message_input.addEventListener('keyup', function(){ var a = createCookie('message_2s', message_input.value, 400); }) message_input.addEventListener('keypress', function(){ var a = createCookie('message_2s', message_input.value, 400); }) } function wait_for_message_input(){ var message_input = document.getElementById('message_input') var observer = new MutationObserver(function(mutation){ mutation.forEach(function(){ var message_input = document.getElementById('message_input') if(message_input != null && message_input != 'undefined'){ edit_message() observer.disconnect() } }) }) var config = { attributes: true, childList: true } observer.observe(message_input, config) } if(message_input == null || message_input == 'undefined'){ wait_for_message_input() }else{ edit_message() } // AJAX // var open = window.XMLHttpRequest.prototype.open, send = window.XMLHttpRequest.prototype.send, onReadyStateChange; function openReplacement(method, url, async, user, password) { var syncMode = async !== false ? 'async' : 'sync'; console.warn( 'Preparing ' + syncMode + ' HTTP request : ' + method + ' ' + url ); return open.apply(this, arguments); } function sendReplacement(data) { console.warn('Sending HTTP request data : ', data); var regex_nouveau_topic = /do=topic-create*/ var regex_nouveau_message = /do=message-create*/ if(data.match(regex_nouveau_topic) != null || data.match(regex_nouveau_message) != null){ this.addEventListener('load', function(e) { var regex_error = /\{"error"*/ if(this.responseText.match(regex_error) == null){ clear_message() } else{ } }) } if(this.onreadystatechange) { this._onreadystatechange = this.onreadystatechange; } this.onreadystatechange = onReadyStateChangeReplacement; return send.apply(this, arguments); } function onReadyStateChangeReplacement() { console.warn('HTTP request ready state changed : ' + this.readyState); if(this._onreadystatechange) { return this._onreadystatechange.apply(this, arguments); } } window.XMLHttpRequest.prototype.open = openReplacement; window.XMLHttpRequest.prototype.send = sendReplacement; })();