1. // ==UserScript==
  2. // @name         MQTT
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match       https://fptplay.vn/livetv*
  8. // @grant        none
  9. // @require      http://code.jquery.com/jquery-3.3.1.min.js
  10. // @require      https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js
  11. // ==/UserScript==
  12. var client;
  13. (function() {
  14.     'use strict';
  15.     //$('a').text('hiển');
  16.  
  17.     // Your code here...
  18.     // Create a client instance
  19.   client = new Paho.MQTT.Client("m12.cloudmqtt.com", 32705, "123456web_" + parseInt(math.random() * 1000, 10));
  20.  
  21.   // set callback handlers
  22.   client.onConnectionLost = onConnectionLost;
  23.   client.onMessageArrived = onMessageArrived;
  24.   var options = {
  25.     useSSL: true,
  26.     userName: "wwfptvbl",
  27.     password: "hqvP7bmVIU0h",
  28.     onSuccess:onConnect,
  29.     onFailure:doFail
  30.   }
  31.  
  32.   // connect the client
  33.   client.connect(options);
  34. })();
  35.  
  36. // called when the client connects
  37.   function onConnect() {
  38.     // Once a connection has been made, make a subscription and send a message.
  39.     console.log("onConnect");
  40.     client.subscribe('hienlt/chanel');
  41.   }
  42.  
  43.   function doFail(e){
  44.     console.log(e);
  45.   }
  46.  
  47.   // called when the client loses its connection
  48.   function onConnectionLost(responseObject) {
  49.     if (responseObject.errorCode !== 0) {
  50.       console.log("onConnectionLost:"+responseObject.errorMessage);
  51.     }
  52.   }
  53.  
  54.   // called when a message arrives
  55.   function onMessageArrived(message) {
  56.     console.log("onMessageArrived:"+message);
  57.       var selectedChannel = $('.tv_channel.active').first();
  58.       if (message.payloadString == 'next') {
  59.          selectedChannel.parent().parent().next().find('.tv_channel').first().click();
  60.       }else if(message.payloadString == 'prev'){
  61.          selectedChannel.parent().parent().prev().find('.tv_channel').first().click();
  62.       }else{
  63.          $("a.tv_channel[data-href*='"+message.payloadString+"']").first().click();
  64.       }
  65.   }