Advertisement
Farbjodr

Automeh string/regex

Jun 24th, 2015
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Automeh
  3. // @version      0.2
  4. // @description  /meh add "string" or /regex/ ; /meh del "string" or /regex/ ; /meh list ; /meh share ; /meh clear ; /meh this
  5. // @author       Ravana
  6. // @match        https://plug.dj/*
  7. // @require http://code.jquery.com/jquery-latest.js
  8. // ==/UserScript==
  9.  
  10. setTimeout(function() {
  11.     var mehTriggers = [];
  12.     if(localStorage["mehTriggers"]){
  13.         mehTriggers = JSON.parse(localStorage["mehTriggers"]);
  14.     }
  15.    
  16.     API.on(API.CHAT_COMMAND, function(arg){
  17.         var data = arg.split(" ");
  18.         if(data[0]!="/meh")return;
  19.         if(data[1]=="add"){
  20.             data.shift();
  21.             data.shift();
  22.             data = data.join(" ");
  23.             if(data[0]=='"' && data.slice(-1)=='"'){
  24.             } else {
  25.                 if(data[0]=='/' && data.slice(-1)=='/'){
  26.                 } else {
  27.                     API.chatLog('Invalid input. Usage: /meh add "string" or /regex/');
  28.                     return;
  29.                 }
  30.             }
  31.             mehTriggers.push(data);
  32.             localStorage["mehTriggers"] = JSON.stringify(mehTriggers);
  33.             API.chatLog("Automeh trigger added: "+data);
  34.         }
  35.         if(data[1]=="del"){
  36.             data.shift();
  37.             data.shift();
  38.             data = data.join(" ");
  39.             var index = mehTriggers.indexOf(data);
  40.             if (index >= 0) {
  41.                 mehTriggers.splice( index, 1 );
  42.                 localStorage["mehTriggers"] = JSON.stringify(mehTriggers);
  43.                 API.chatLog("Automeh trigger removed: "+data);
  44.             }
  45.         }
  46.         if(data[1]=="list"){
  47.             API.chatLog(mehTriggers.join(" | "));
  48.             // need something else for long list
  49.         }
  50.         if(data[1]=="this"){
  51.             data = '"'+API.getMedia().author.toLowerCase() + " - " + API.getMedia().title.toLowerCase()+'"';
  52.             mehTriggers.push(data);
  53.             localStorage["mehTriggers"] = JSON.stringify(mehTriggers);
  54.             API.chatLog("Automeh trigger added: "+data);
  55.         }
  56.         if(data[1]=="share"){
  57.             API.sendChat("My Automeh matches: "+mehTriggers.join(" | "));
  58.             // need something else for long list
  59.         }
  60.         if(data[1]=="clear"){
  61.             API.chatLog("Automeh matches cleared: "+mehTriggers.join(" | "));
  62.             mehTriggers=[];
  63.             localStorage["mehTriggers"] = "";
  64.         }
  65.     })
  66.    
  67.     API.on(API.ADVANCE,function(data){
  68.         var title = data.media.author.toLowerCase() + " - " + data.media.title.toLowerCase();
  69.         mehTriggers.forEach(function(entry) {
  70.             if(entry[0]=='"'){
  71.                 // STRING MATCH
  72.                 entry = entry.slice(1, -1);
  73.                 if(title.indexOf(entry)>-1){
  74.                     API.chatLog("Automeh string match found with "+entry);
  75.                     $("#meh").click();
  76.                     setTimeout(function(){$("#meh").click()},10000);
  77.                     return;
  78.                 }
  79.             }
  80.             if(entry[0]=='/'){
  81.                 // REGEX MATCH
  82.                 entry = entry.slice(1, -1);
  83.                 var reg = new RegExp(entry);
  84.                 if(title.match(reg)){
  85.                     API.chatLog("Automeh regex match found with "+entry);
  86.                     $("#meh").click();
  87.                     setTimeout(function(){$("#meh").click()},10000);
  88.                     return;
  89.                 }
  90.             }
  91.         });
  92.     })
  93. },10000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement