SirBard

Lobbylink Linker for Unityhacks.com Shoutbox

Dec 11th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Lobbylink Linker for Unityhacks.com Shoutbox
  3. // @namespace    https://www.unityhacks.com/members/sirbard.28069/
  4. // @version      0.1
  5. // @description  Replaces plain text lobby links with clickable lobby links
  6. // @author       SirBard
  7. // @match        https://www.unityhacks.com/
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.     var config = {
  14.         speed: 1000,
  15.         link_css: "color:red;text-decoration:underline",
  16.         container: "#taigachat_box",
  17.         message: ".taigachat_messagetext",
  18.     };
  19.     var mod = {
  20.         init: function(){
  21.             var _ = this;
  22.             setInterval(function(){
  23.                 _.render();
  24.             },config.speed);
  25.         },
  26.         render: function(){
  27.             var _ = this;
  28.             $(config.container).find(config.message).each(function(){
  29.                 var lineHTML = $(this).html();
  30.                 if( lineHTML.indexOf("<a href") === -1 && lineHTML.indexOf("steam://") !== -1 ){
  31.                     $(this).html(_.replace(lineHTML));
  32.                 }
  33.             });
  34.         },
  35.         replace: function(text){
  36.             return text.replace(/(\b(steam):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i,"<a href='$1' style='"+config.link_css+"'>$1</a>");
  37.         }
  38.     };
  39.     mod.init();
  40. })();
Add Comment
Please, Sign In to add comment