Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- 'use strict';
- var interval = 60000;
- if( window.location.href.indexOf("youtube") > -1 ){
- $.docReady = function(data) {
- return $( document).ready(data);
- };
- $.getTitle = function(){
- return document.title;
- };
- }
- function urlToEpisode(url){
- return '';
- }
- $.docReady(function (){
- var token = '';
- if(GM_getValue('token', 0)){
- token = GM_getValue('token');
- }else{
- token = prompt("Entre le token de connexion.\nRegardez la description si besoin");
- GM_setValue('token', token);
- }
- var client = new Discord.Client({
- token: token,
- autorun: true
- });
- client.on('ready', function() {
- console.log("%s (%s)... in the browser!", client.username, client.id);
- GM_deleteValue('timeLeft');
- setInterval(function(){ setgame(); }, interval);
- setgame();
- });
- client.on('disconnect', function(errMsg, code) {
- alert(errMsg);
- if(code == 4004){
- GM_deleteValue('token');
- }
- });
- function setgame() {
- var timeLeft = '';
- if( typeof $('video').get(0) != 'undefined' ){
- var duration = $('video').get(0).duration;
- var current = $('video').get(0).currentTime;
- timeLeft = Math.ceil((duration - current) / 60);
- if(timeLeft == null || timeLeft == 0 || isNaN(timeLeft)){
- timeLeft = '';
- }else{
- timeLeft = "( -"+timeLeft+" Min )";
- }
- }
- if( timeLeft == '' && GM_getValue('timeLeft', '') != ''){
- timeLeft = GM_getValue('timeLeft', '');
- GM_deleteValue('timeLeft');
- }
- var episode = urlToEpisode(window.location.href);
- if(episode == null || episode == 0 || isNaN(episode)){
- episode = '';
- }else{
- episode = 'Ep. '+ episode;
- }
- client.setPresence({
- game:{
- name: $.getTitle() +" "+ episode +" "+ timeLeft ,
- type: 3
- }
- });
- console.log('Set Game', $.getTitle() +" "+ episode +" "+ timeLeft);
- }
- $( window ).unload(function() {
- client.setPresence({ game:{ name:"", } });
- });
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement