radiant.js
Version:
Browser-side JS library Extending GMusic.js For Radiant Player
1,188 lines (956 loc) • 93.4 kB
JavaScript
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Radiant=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _assert = _dereq_('assert');
var _assert2 = _interopRequireDefault(_assert);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var RadiantNamespace = function () {
function RadiantNamespace(emit, on) {
_classCallCheck(this, RadiantNamespace);
this.emit = emit;
this.on = on;
this.prototype = {};
}
_createClass(RadiantNamespace, [{
key: '_mapSelectors',
value: function _mapSelectors(selectors) {
var _this = this;
Object.keys(selectors).forEach(function (selectorKey) {
Object.defineProperty(_this, '_' + selectorKey + 'El', {
get: function get() {
var elem = document.querySelector(selectors[selectorKey]);
(0, _assert2.default)(elem, 'Failed to find ' + selectorKey + ' element for ' + _this.constructor + ': "' + selectors[selectorKey] + '"');
return elem;
}
});
});
}
}, {
key: 'addMethod',
value: function addMethod(methodName) {
this.prototype[methodName] = this[methodName].bind(this);
}
}, {
key: 'addMethods',
value: function addMethods(methodNames) {
var _this2 = this;
methodNames.forEach(function (methodName) {
return _this2.addMethod(methodName);
});
}
}, {
key: 'getPrototype',
value: function getPrototype() {
return this.prototype;
}
}]);
return RadiantNamespace;
}();
exports.default = RadiantNamespace;
},{"assert":11}],2:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var songSelectors = exports.songSelectors = {
SongID: ".song-row.currently-playing",
SongAlbumID: ".player-album",
SongArtist: "player-artist",
SongTitle: "currently-playing-title",
SongAlbum: ".player-album",
SongAlbumBuyLink: "buy-button-player",
SongYouTubeID: "youtubeId",
SongYouTubeSection: ".now-playing-actions",
playPause: '[data-id="play-pause"]'
};
var controlsSelectors = exports.controlsSelectors = {
playPause: '[data-id="play-pause"]',
repeat: '[data-id="repeat"]',
rewind: '[data-id="rewind"]',
forward: '[data-id="forward"]',
play: '[data-id="play"]',
materialcard: '.material-card'
};
var playbackSelectors = exports.playbackSelectors = {
progress: '#material-player-progress'
};
var nowPlayingSelectors = exports.nowPlayingSelectors = {
albumArt: '#playerBarArt',
albumName: '.player-album',
artistName: '#player-artist',
nowPlayingContainer: '#playerSongInfo',
infoWrapper: '.now-playing-info-wrapper',
title: '#currently-playing-title'
};
},{}],3:[function(_dereq_,module,exports){
'use strict';
var _radiant = _dereq_('./radiant');
var _radiant2 = _interopRequireDefault(_radiant);
var _RadiantNamespace = _dereq_('./RadiantNamespace');
var _RadiantNamespace2 = _interopRequireDefault(_RadiantNamespace);
var _Song = _dereq_('./structs/Song');
var _Song2 = _interopRequireDefault(_Song);
var _Artwork = _dereq_('./structs/Artwork');
var _Artwork2 = _interopRequireDefault(_Artwork);
var _Share = _dereq_('./structs/Share');
var _Share2 = _interopRequireDefault(_Share);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_radiant2.default.RadiantNamespace = _RadiantNamespace2.default;
_radiant2.default.Song = _Song2.default;
_radiant2.default.Artwork = _Artwork2.default;
_radiant2.default.Share = _Share2.default;
module.exports = _radiant2.default;
},{"./RadiantNamespace":1,"./radiant":7,"./structs/Artwork":8,"./structs/Share":9,"./structs/Song":10}],4:[function(_dereq_,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _RadiantNamespace2 = _dereq_('../RadiantNamespace');
var _RadiantNamespace3 = _interopRequireDefault(_RadiantNamespace2);
var _LanguageNamespace = _dereq_('./LanguageNamespace');
var _LanguageNamespace2 = _interopRequireDefault(_LanguageNamespace);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var FunctionsNamespace = function (_RadiantNamespace) {
_inherits(FunctionsNamespace, _RadiantNamespace);
function FunctionsNamespace() {
var _ref;
_classCallCheck(this, FunctionsNamespace);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _this = _possibleConstructorReturn(this, (_ref = FunctionsNamespace.__proto__ || Object.getPrototypeOf(FunctionsNamespace)).call.apply(_ref, [this].concat(args)));
_this.addMethods(['create', 'Replace', 'hasClass', 'has', 'Retry', 'trigger', 'getID', 'FakeClick', 'FakeMenuClick', 'Playing', 'Volume', 'IMFL', 'getYoutubeID', 'RollDice', 'Observe', '_textContent']);
_this.language = new _LanguageNamespace2.default();
return _this;
}
/**
* Add Elements to the DOM
* @param Baraka
* @returns {DocumentFragment}
*/
_createClass(FunctionsNamespace, [{
key: 'create',
value: function create(Baraka) {
var radiant = document.createDocumentFragment();
var temp = document.createElement('div');
temp.innerHTML = Baraka;
while (temp.firstChild) {
radiant.appendChild(temp.firstChild);
}
return radiant;
}
/**
* Replace a string with something else
* @param s
* @param f
* @param r
* @returns {*}
* @constructor
*/
}, {
key: 'Replace',
value: function Replace(s, f, r) {
if (s === null) {
return false;
} else {
return s.replace(new RegExp(f, 'g'), r);
}
}
/**
* Check is element has a added / set class in element attribute
* @param element
* @param cls
* @returns {boolean}
*/
}, {
key: 'hasClass',
value: function hasClass(element, cls) {
if (element !== null) {
return (' ' + element.className + ' ').includes(' ' + cls + ' ');
} else {
return false;
}
}
/**
* Check if Object has KEY property as a match other wise it's false
* @param obj
* @param value
* @returns {boolean}
*/
}, {
key: 'has',
value: function has(obj, value) {
for (var id in obj) {
if (obj[id] === value) {
return true;
}
}
return false;
}
/**
* Emulate a Delay
* @param isDone
* @param next
* @constructor
*/
}, {
key: 'Retry',
value: function Retry(isDone, next) {
var currentTrial = 0;
var maxRetry = 50;
var interval = 10;
var isTimeout = false;
var id = window.setInterval(function () {
if (isDone()) {
window.clearInterval(id);
next(isTimeout);
}
if (currentTrial++ > maxRetry) {
window.clearInterval(id);
isTimeout = true;
next(isTimeout);
}
}, 10);
}
/**
* Simulate a mouse event
* @param node
* @param eventType
*/
}, {
key: 'trigger',
value: function trigger(node, eventType) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(eventType, true, true);
node.dispatchEvent(clickEvent);
}
/**
* Get ID by a url / string
* @param s
* @returns {*}
*/
}, {
key: 'getID',
value: function getID(s) {
var t = s.split(/[\\\/]/)[5].match(/\S[^?]*(?:\?+|$)/g)[0].slice(0, -1);
return t.match("t=") ? this.language.NoSongID() : t;
}
/**
* Send a FakeClick() trigger to the DOM to get data queue
* @constructor
*/
}, {
key: 'FakeClick',
value: function FakeClick() {
this.Retry(function isDone() {
document.querySelector('[id="queue-overlay"]').style.opacity = 0;
document.querySelector('[data-id="queue"]').click();
document.querySelector('[id="queue-overlay"]').style.width = "0px";
document.querySelector("#queue-overlay").close();
return false;
}, function next(isTimeout) {
if (isTimeout) {
document.querySelector('[id="queue-overlay"]').style.width = null;
document.querySelector('[id="queue-overlay"]').style.opacity = null;
document.querySelector('body').click();
}
});
}
/**
* Send a FakeMenuClick() trigger to the DOM to get data song id / info
* @constructor
*/
}, {
key: 'FakeMenuClick',
value: function FakeMenuClick() {
if (document.body.contains(document.querySelector('.song-menu')) && this.Playing()) {
if (document.querySelector('[data-id=\"now-playing-menu\"]') !== null) {
document.querySelector('[data-id=\"now-playing-menu\"]').click();
this.trigger(document.querySelector('[data-id=\"now-playing-menu\"]'), "mousedown");
this.trigger(document.querySelector('[data-id=\"now-playing-menu\"]'), "mouseup");
this.trigger(document.querySelector('.song-menu'), "mouseover");
this.trigger(document.querySelector('.song-menu .goog-menuitem[id*=":f"]'), "mouseover");
this.trigger(document.querySelector('.song-menu .goog-menuitem[id*=":f"]'), "mousedown");
this.trigger(document.querySelector('.song-menu .goog-menuitem[id*=":f"]'), "mouseup");
document.querySelector('[class*="get-link"]').style.opacity = 0;
window.RadiantState.SongID = this.getID(document.querySelector('[class*="get-link"] #labelAndInputContainer input').value);
this.trigger(document.querySelector('body'), "mousedown");
document.querySelector('[class*="get-link"]').parentNode.removeChild(document.querySelector('[class*="get-link"]'));
}
}
}
/**
* Check if Google Play Music is playing a song
* @returns {*|boolean}
* @constructor
*/
}, {
key: 'Playing',
value: function Playing() {
return this.hasClass(document.querySelector('[id="player-bar-play-pause"]'), "playing");
}
/**
* Get the current Volume on gpm
* @returns {*}
* @constructor
*/
}, {
key: 'Volume',
value: function Volume() {
return window.RadiantState.volume_state === null ? 100 : gmusic.volume.getVolume();
}
/**
* Are you Feeling Lucky? Cause We are! Roll the Dice
* @constructor
*/
}, {
key: 'IMFL',
value: function IMFL() {
var lucky = this.create('<div class="material-card" data-type="imfl" style="display:none"></div><div class="ad-preroll-container ad-preroll-container-hidden" style="display:none"><div class=ad-preroll-video-container><div style=position:absolute><iframe allowfullscreen src=https://imasdk.googleapis.com/js/core/bridge3.166.0_en.html#goog_855622984 style=border:0;opacity:0;margin:0;padding:0;position:relative></iframe></div></div><div class=ad-preroll-message-container><div class=ad-preroll-message-text>Subscribe for all of the music on-demand and offline with none of the ads</div><div><paper-button animated=""aria-disabled=false class="paper-button-0 upsell-button x-scope"data-id=upgrade elevation=0 role=button tabindex=0>SUBSCRIBE</paper-button></div></div><div class=ad-preroll-companion-container></div></div>');
var readyStateChecker = setInterval(function () {
if (document.readyState === "complete") {
document.body.insertBefore(lucky, document.body.childNodes[0]);
clearInterval(readyStateChecker);
}
}, 10);
}
/**
* Get the current song's YouTube id if any
* @returns {string | null}
*/
}, {
key: 'getYoutubeID',
value: function getYoutubeID() {
return window.RadiantState.SongYouTubeID;
}
/**
* IMFL has been inserted so lets Roll the Dice!!
* @constructor
*/
}, {
key: 'RollDice',
value: function RollDice() {
document.querySelector('[data-type=\"imfl\"]').click();
}
/**
* Check and wait to see that GMusic initialization was defined
* @constructor
*/
}, {
key: 'Observe',
value: function Observe() {
var check = setInterval(function () {
if (typeof gmusic !== "undefined") {
window.RadiantState.ready = !!1;
clearInterval(check);
}
}, 10);
}
}, {
key: '_textContent',
value: function _textContent(el, defaultText) {
return el ? el.textContent || defaultText : defaultText;
}
}]);
return FunctionsNamespace;
}(_RadiantNamespace3.default);
exports.default = FunctionsNamespace;
},{"../RadiantNamespace":1,"./LanguageNamespace":6}],5:[function(_dereq_,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _RadiantNamespace2 = _dereq_('../RadiantNamespace');
var _RadiantNamespace3 = _interopRequireDefault(_RadiantNamespace2);
var _Artwork = _dereq_('../structs/Artwork');
var _Artwork2 = _interopRequireDefault(_Artwork);
var _Song2 = _dereq_('../structs/Song');
var _Song3 = _interopRequireDefault(_Song2);
var _Share2 = _dereq_('../structs/Share');
var _Share3 = _interopRequireDefault(_Share2);
var _FunctionsNamespace = _dereq_('./FunctionsNamespace');
var _FunctionsNamespace2 = _interopRequireDefault(_FunctionsNamespace);
var _LanguageNamespace = _dereq_('./LanguageNamespace');
var _LanguageNamespace2 = _interopRequireDefault(_LanguageNamespace);
var _selectors = _dereq_('../constants/selectors');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var HelpersNamespace = function (_RadiantNamespace) {
_inherits(HelpersNamespace, _RadiantNamespace);
function HelpersNamespace() {
var _ref;
_classCallCheck(this, HelpersNamespace);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _this = _possibleConstructorReturn(this, (_ref = HelpersNamespace.__proto__ || Object.getPrototypeOf(HelpersNamespace)).call.apply(_ref, [this].concat(args)));
_this.language = new _LanguageNamespace2.default();
_this.fn = new _FunctionsNamespace2.default();
_this.startUp(_this.fn);
_this._mapSelectors(_selectors.playbackSelectors);
_this.addMethods(['replayBack', 'replayFor', 'getVolume', 'Region', 'SongAlbumArt', 'Song', 'hasYoutube', 'Share', 'getPlaybackState', 'adState', 'RadiantHandler']);
_this._hookEvents();
return _this;
}
/**
* Set the song's progress to go back and forward in time by intervals or get player states
* @type {{replayBack: Function, replayFor: Function, getVolume: Function}}
*/
_createClass(HelpersNamespace, [{
key: 'replayBack',
value: function replayBack() {
return gmusic.playback.rewindTen();
}
}, {
key: 'replayFor',
value: function replayFor() {
return gmusic.playback.forwardThirty();
}
/**
* Helper function to get the Volume
* @returns int
*/
}, {
key: 'getVolume',
value: function getVolume() {
return this.fn.Volume();
}
/**
* Check what Region you are in
* @type {{Region}}
*/
}, {
key: 'Region',
value: function Region() {
if (window.gbar.hasOwnProperty("_CONFIG")) {
return window.gbar._CONFIG[0][0][19].length === 0 ? this.language.NoGeo() : window.gbar._CONFIG[0][0][19];
} else {
return this.language.NoConfig();
}
}
/**
* This provides information for Song Art items that are playing by getting
* @type {{Artwork: {Full: *, Large: *, Medium: *, Small: *, Mini: string}}}
*/
}, {
key: 'SongAlbumArt',
value: function SongAlbumArt() {
var artwork = new _Artwork2.default({
Full: this.fn.Replace(document.querySelector(_selectors.nowPlayingSelectors.albumArt).getAttribute('src'), 's90', "s0"),
Large: this.fn.Replace(document.querySelector(_selectors.nowPlayingSelectors.albumArt).getAttribute('src'), 's90', "s800"),
Medium: this.fn.Replace(document.querySelector(_selectors.nowPlayingSelectors.albumArt).getAttribute('src'), 's90', "s500"),
Small: this.fn.Replace(document.querySelector(_selectors.nowPlayingSelectors.albumArt).getAttribute('src'), 's90', "s300"),
Mini: document.querySelector(_selectors.nowPlayingSelectors.albumArt).getAttribute('src')
});
window.RadiantState.Artwork = artwork;
return artwork;
}
/**
* This provides information for items that are playing by getting :
* {SongID: string, SongAlbumID: string, SongArtist: string, SongTitle: string, SongAlbum: string, SongAlbumBuyLink: string}, SongID: string, SongAlbumID: string, SongArtist: string, SongTitle: string, SongAlbum: string, SongAlbumBuyLink: string, SongYouTubeID: string}
* T2f7kfchlqqc4rx2bugxcnm42ke == f68db999-5f6c-35b5-8fcd-b5b052e203b3 GUID / Hex ?
* @returns {Song}
* @constructor
*/
}, {
key: 'Song',
value: function Song() {
var nowPlayingContainer = document.querySelector(_selectors.nowPlayingSelectors.nowPlayingContainer);
var id = document.querySelector(_selectors.songSelectors.SongAlbumID) !== null ? document.querySelector(_selectors.songSelectors.SongAlbumID).getAttribute('data-id') : "album/";
this.fn.FakeClick();
this.fn.FakeMenuClick();
var song = new _Song3.default({
SongID: window.RadiantState.SongID,
SongAlbumID: document.querySelector(_selectors.songSelectors.SongAlbumID) !== null ? document.querySelector(_selectors.songSelectors.SongAlbumID).getAttribute('data-id').substring(0, id.indexOf('/')) : 'Unknown Album ID',
SongTitle: this.fn._textContent(nowPlayingContainer.querySelector(_selectors.nowPlayingSelectors.title), 'Unknown Title'),
SongArtist: this.fn._textContent(nowPlayingContainer.querySelector(_selectors.nowPlayingSelectors.artistName), 'Unknown Artist'),
SongAlbum: document.querySelector(_selectors.songSelectors.SongAlbum) !== null ? this.fn._textContent(nowPlayingContainer.querySelector(_selectors.nowPlayingSelectors.albumName), 'Unknown Album') : 'Unknown Album',
SongAlbumBuyLink: document.querySelector(_selectors.songSelectors.SongAlbumBuyLink) !== null ? this.fn._textContent(document.querySelector(_selectors.songSelectors.SongAlbumBuyLink).querySelector("a").getAttribute("href").replace(/\s+/g, ''), this.language.Not()) : this.language.Not(),
SongYouTubeID: this.hasYoutube() ? document.querySelector(_selectors.songSelectors.SongID) !== null ? document.querySelector(_selectors.songSelectors.SongID).dataset[_selectors.songSelectors.SongYouTubeID] : this.language.NoYouTube() : this.language.NoYouTube()
});
window.RadiantState.Song = song;
window.RadiantState.SongYouTubeID = song.SongYouTubeID;
window.RadiantState.volume_state = this.fn.Volume();
return song;
}
/**
* Get a playing state, this function was adopted from GMusic
* @returns {number}
*/
}, {
key: 'getPlaybackState',
value: function getPlaybackState() {
var playButton = document.querySelector(_selectors.controlsSelectors.playPause);
if (playButton.classList.contains('playing')) {
return HelpersNamespace.ENUMS.PlaybackStatus.PLAYING;
}
if (!playButton.disabled) {
if (playButton.__data__.icon === 'av:pause-circle-filled') {
return HelpersNamespace.ENUMS.PlaybackStatus.PLAYING;
}
return HelpersNamespace.ENUMS.PlaybackStatus.PAUSED;
}
return HelpersNamespace.ENUMS.PlaybackStatus.STOPPED;
}
/**
* Get a playing state of Ads
* @returns {number}
*/
}, {
key: 'adState',
value: function adState() {
var ad = document.querySelector(".ad-preroll-container") !== null ? document.querySelector(".ad-preroll-container") : null;
if (ad !== null) {
if (ad.className === 'ad-preroll-container') {
return HelpersNamespace.ENUMS.AdsStatus.PLAYING;
}
if (ad.className === 'ad-preroll-container ad-preroll-container-hidden') {
return HelpersNamespace.ENUMS.AdsStatus.STOPPED;
}
}
return HelpersNamespace.ENUMS.AdsStatus.STOPPED;
}
/**
* Get Google Play Music Share links
* @type {{Types, Services: {Assign}}}
*/
}, {
key: 'Share',
value: function Share() {
var Facebook_type = "https://play.google.com/music/m/" + window.RadiantState.SongID + "?utm_medium=organic_share&utm_source=facebook&redirect_uri=https://play.google.com/music/returnfromshare";
var Twitter_type = "https://play.google.com/music/m/" + window.RadiantState.SongID + "?utm_medium=organic_share&utm_source=twitter";
var Facebook = "https://www.facebook.com/dialog/share?app_id=1618370355114238&display=popup&href=" + encodeURIComponent(Facebook);
var Twitter = "https://twitter.com/intent/tweet?url=" + encodeURIComponent(Twitter);
var Normal = "https://play.google.com/music/m/" + window.RadiantState.SongID;
var share = new _Share3.default({
Facebook_type: Facebook_type,
Twitter_type: Twitter_type,
Facebook: Facebook,
Twitter: Twitter,
Normal: Normal
});
window.RadiantState.Share.Types.F = Facebook_type;
window.RadiantState.Share.Types.T = Twitter_type;
window.RadiantState.Share.Services.Normal = "https://play.google.com/music/m/" + window.RadiantState.SongID;
window.RadiantState.Share.Services.Facebook = "https://www.facebook.com/dialog/share?app_id=1618370355114238&display=popup&href=" + encodeURIComponent(Facebook);
window.RadiantState.Share.Services.Twitter = "https://twitter.com/intent/tweet?url=" + encodeURIComponent(Twitter);
return share;
}
/**
* Determine if our player has any Youtube when playing
* @returns {*|boolean}
*/
}, {
key: 'hasYoutube',
value: function hasYoutube() {
return this.fn.hasClass(document.querySelector(_selectors.songSelectors.SongYouTubeSection), "has-youtube");
}
/**
* Listen to {forward} and {rewind} clicks and re-add correct re-time data with Retry
* @param Baraka
* @constructor
*/
}, {
key: 'RadiantHandler',
value: function RadiantHandler(currentTrack, currentArt, currentShare, lan, Baraka) {
if (Baraka === "playRow") {
if (document.querySelector(".song-row .column-content [data-id='play']") !== null) {
document.querySelector(".song-row .column-content [data-id='play']").addEventListener("click", this.RadiantHandler(currentTrack, currentArt, currentShare, lan, ""), false);
}
}
if (Baraka === "playMcard") {
if (document.querySelector(".material-card .play-button") !== null) {
document.querySelector(".material-card .play-button").addEventListener("click", this.RadiantHandler(currentTrack, currentArt, currentShare, lan, ""), false);
}
}
var Playing = document.querySelector("[data-id='play-pause']").classList.contains('playing');
var Language = lan;
var fn = this.fn;
this.fn.Retry(function isDone() {
/* window.RadiantState.SongYouTubeID = Language.NoYouTube();
window.RadiantState.SongID = Language.NoSong();
window.RadiantState.Song = Language.NoSong();
window.RadiantState.Artwork = Language.NoSong();
window.RadiantState.Ads = Language.NoAds();
window.RadiantState.volume_state = fn.Volume();
window.RadiantState.Share.Services.Facebook = null;
window.RadiantState.Share.Services.Twitter = null;
window.RadiantState.Share.Services.Normal = null;
window.RadiantState.Share.Types['F'] = null;
window.RadiantState.Share.Types['T'] = null;
window.RadiantState.Share.Types['Normal'] = null;*/
return false;
}, function next(isTimeout) {
if (isTimeout) {
if (Playing) {
currentTrack;
currentArt;
currentShare;
}
}
});
}
/**
* Emit our events on the dom
* @private
*/
}, {
key: '_hookEvents',
value: function _hookEvents() {
var _this2 = this;
// Change Track Event
var lastTrack = void 0;
var lastArt = void 0;
var lastShare = void 0;
new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
for (var i = 0; i < m.addedNodes.length; i++) {
// DEV: We can encounter a text node, verify we have a `classList` to assert against
var target = m.addedNodes[i];
if (target.classList && target.classList.contains('now-playing-info-wrapper')) {
var currentTrack = _this2.Song();
var currentArt = _this2.SongAlbumArt();
var currentShare = _this2.Share();
// Make sure that this is the first of the notifications for the
// insertion of the song information elements.
if (!currentTrack.equals(lastTrack)) {
_this2.emit('change:radiant', { song: currentTrack, art: currentArt, share: currentShare });
lastTrack = currentTrack;
lastArt = currentArt;
lastShare = currentShare;
var forward = document.querySelector(_selectors.controlsSelectors.forward).addEventListener("click", _this2.RadiantHandler(currentTrack, currentArt, currentShare, _this2.language, ""), false);
var rewind = document.querySelector(_selectors.controlsSelectors.rewind).addEventListener("click", _this2.RadiantHandler(currentTrack, currentArt, currentShare, _this2.language, ""), false);
var play = document.querySelector(_selectors.controlsSelectors.play).addEventListener("click", _this2.RadiantHandler(currentTrack, currentArt, currentShare, _this2.language, ""), false);
if (document.querySelector(_selectors.controlsSelectors.materialcard) !== null) {
var playMcard = document.querySelector(_selectors.controlsSelectors.materialcard).addEventListener("mouseover", _this2.RadiantHandler(currentTrack, currentArt, currentShare, _this2.language, "playMcard"), false);
}
}
}
}
});
}).observe(document.querySelector(_selectors.nowPlayingSelectors.nowPlayingContainer), {
childList: true,
subtree: true
});
// Play/Pause Event
var lastMode = void 0;
new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
if (m.target.dataset.id === 'play-pause') {
var currentMode = _this2.getPlaybackState();
// If the mode has changed, then update it
if (currentMode !== lastMode) {
_this2.emit('change:radiant-playback', currentMode);
if (currentMode === 0) {
window.RadiantState.SongYouTubeID = _this2.language.NoYouTube();
window.RadiantState.SongID = _this2.language.NoSong();
window.RadiantState.Song = _this2.language.NoSong();
window.RadiantState.Artwork = _this2.language.NoSong();
window.RadiantState.Ads = _this2.language.NoAds();
window.RadiantState.Share.Services.Facebook = null;
window.RadiantState.Share.Services.Twitter = null;
window.RadiantState.Share.Services.Normal = null;
window.RadiantState.Share.Types['F'] = null;
window.RadiantState.Share.Types['T'] = null;
window.RadiantState.Share.Types['Normal'] = null;
}
if (currentMode === 2 || currentMode === 1) {
_this2.Song();
_this2.SongAlbumArt();
_this2.Share();
window.RadiantState.volume_state = _this2.fn.Volume();
}
lastMode = currentMode;
}
}
});
}).observe(document.querySelector(_selectors.controlsSelectors.playPause), {
attributes: true
});
var readyStateChecker = setInterval(function () {
if (document.readyState === "complete") {
/* Ad Playing Event */
var lastAdMode = void 0;
new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
var currentAdMode = _this2.adState();
if (m.target.className === 'ad-preroll-container ad-preroll-container-hidden') {
if (currentAdMode !== lastAdMode) {
if (currentAdMode === 0) {
_this2.emit('change:ad', _this2.language.NoAds());
window.RadiantState.Ads = _this2.language.NoAds();
}
if (currentAdMode === 2) {
_this2.emit('change:ad', _this2.language.AdPlaying());
window.RadiantState.Ads = _this2.language.AdPlaying();
}
lastAdMode = currentAdMode;
}
} else {
if (currentAdMode !== lastAdMode) {
if (currentAdMode === 0) {
_this2.emit('change:ad', _this2.language.NoAds());
window.RadiantState.Ads = _this2.language.NoAds();
}
if (currentAdMode === 2) {
_this2.emit('change:ad', _this2.language.AdPlaying());
window.RadiantState.Ads = _this2.language.AdPlaying();
}
lastAdMode = currentAdMode;
}
}
});
}).observe(document.querySelector(".ad-preroll-container"), {
childList: true,
subtree: true,
attributes: true
});
clearInterval(readyStateChecker);
}
}, 10);
this.fn.Retry(function isDone() {
return false;
}, function next(isTimeout) {
if (isTimeout) {
if (window.RadiantState.ready) {
//window.RadiantState.volume_state = gmusic.volume.getVolume();
}
}
});
}
/**
* Load Radiant and make sure IMFL is placed so users or yourself can Roll the Dice including a check for GMusic initialization
*/
}, {
key: 'startUp',
value: function startUp(fn) {
fn.Observe();
fn.IMFL();
window.RadiantState.volume_state = fn.Volume();
// All should have passed!
console.log("RadiantTools has been loaded!!");
}
}]);
return HelpersNamespace;
}(_RadiantNamespace3.default);
HelpersNamespace.ENUMS = {
PlaybackStatus: {
STOPPED: 0,
PAUSED: 1,
PLAYING: 2
},
AdsStatus: {
STOPPED: 0,
PLAYING: 2
}
};
exports.default = HelpersNamespace;
},{"../RadiantNamespace":1,"../constants/selectors":2,"../structs/Artwork":8,"../structs/Share":9,"../structs/Song":10,"./FunctionsNamespace":4,"./LanguageNamespace":6}],6:[function(_dereq_,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _RadiantNamespace2 = _dereq_('../RadiantNamespace');
var _RadiantNamespace3 = _interopRequireDefault(_RadiantNamespace2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var LanguageNamespace = function (_RadiantNamespace) {
_inherits(LanguageNamespace, _RadiantNamespace);
function LanguageNamespace() {
var _ref;
_classCallCheck(this, LanguageNamespace);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _this = _possibleConstructorReturn(this, (_ref = LanguageNamespace.__proto__ || Object.getPrototypeOf(LanguageNamespace)).call.apply(_ref, [this].concat(args)));
_this.addMethods(['Not', 'NoSong', 'NoSongID', 'NoYouTube', 'NoAds', 'AdPlaying', 'NoConfig', 'NoGeo']);
return _this;
}
/**
* Language for Not
* @returns {string}
* @constructor
*/
_createClass(LanguageNamespace, [{
key: 'Not',
value: function Not() {
return "You either own this item or you're not playing the radio / an non-owned item";
}
/**
* Language for No Song Playing
* @returns {string}
* @constructor
*/
}, {
key: 'NoSong',
value: function NoSong() {
return "No song is playing";
}
/**
* Language for No Song ID
* @returns {string}
* @constructor
*/
}, {
key: 'NoSongID',
value: function NoSongID() {
return "No song ID found";
}
/**
* Language for No Youtube
* @returns {string}
* @constructor
*/
}, {
key: 'NoYouTube',
value: function NoYouTube() {
return "No YouTube video found";
}
/**
* Language for No Ads
* @returns {string}
* @constructor
*/
}, {
key: 'NoAds',
value: function NoAds() {
return "No Ads Playing";
}
/**
* Language for Ad Playing
* @returns {string}
* @constructor
*/
}, {
key: 'AdPlaying',
value: function AdPlaying() {
return "Ad is playing";
}
/**
* Language for No Config
* @returns {string}
* @constructor
*/
}, {
key: 'NoConfig',
value: function NoConfig() {
return "_CONFIG Not found :(";
}
/**
* Language for No Geo
* @returns {string}
* @constructor
*/
}, {
key: 'NoGeo',
value: function NoGeo() {
return "No Geo Data";
}
}]);
return LanguageNamespace;
}(_RadiantNamespace3.default);
exports.default = LanguageNamespace;
},{"../RadiantNamespace":1}],7:[function(_dereq_,module,exports){
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _events = _dereq_('events');
var _events2 = _interopRequireDefault(_events);
var _LanguageNamespace = _dereq_('./namespaces/LanguageNamespace');
var _LanguageNamespace2 = _interopRequireDefault(_LanguageNamespace);
var _FunctionsNamespace = _dereq_('./namespaces/FunctionsNamespace');
var _FunctionsNamespace2 = _interopRequireDefault(_FunctionsNamespace);
var _HelpersNamespace = _dereq_('./namespaces/HelpersNamespace');
var _HelpersNamespace2 = _interopRequireDefault(_HelpersNamespace);
var _selectors = _dereq_('./constants/selectors');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var namespaces = {};
window.RadiantState = {
ready: !1,
volume_state: null,
SongID: null,
SongYouTubeID: null,
Ads: null,
Share: {
Types: {
"F": !1,
"T": !1,
"Normal": !1
},
Services: {
Facebook: "",
Twitter: ""
}
}
};
var Radiant = function (_Emitter) {
_inherits(Radiant, _Emitter);
function Radiant(props) {
_classCallCheck(this, Radiant);
var _this = _possibleConstructorReturn(this, (Radiant.__proto__ || Object.getPrototypeOf(Radiant)).call(this, props));
Object.keys(namespaces).forEach(function (namespaceName) {
var namespaceClasses = namespaces[namespaceName];
namespaceClasses.forEach(function (NamespaceClass) {
var namespace = new NamespaceClass(_this.emit.bind(_this), _this.on.bind(_this));
_this[namespaceName] = Object.assign(_this[namespaceName] || {}, namespace.getPrototype());
});
});
return _this;
}
_createClass(Radiant, null, [{
key: 'addNamespace',
value: function addNamespace(namespaceName, namespaceClass) {
namespaces[namespaceName] = namespaces[namespaceName] || [];
namespaces[namespaceName].push(namespaceClass);
Object.assign(Radiant, namespaceClass.ENUMS || {});
}
}]);
return Radiant;
}(_events2.default);
Radiant.SELECTORS = { songSelectors: _selectors.songSelectors, playbackSelectors: _selectors.playbackSelectors, nowPlayingSelectors: _selectors.nowPlayingSelectors };
Radiant.addNamespace('languages', _LanguageNamespace2.default);
Radiant.addNamespace('fn', _FunctionsNamespace2.default);
Radiant.addNamespace('Helpers', _HelpersNamespace2.default);
exports.default = Radiant;
},{"./constants/selectors":2,"./namespaces/FunctionsNamespace":4,"./namespaces/HelpersNamespace":5,"./namespaces/LanguageNamespace":6,"events":12}],8:[function(_dereq_,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Artwork = function () {
function Artwork(_ref) {
var Full = _ref.Full,
Large = _ref.Large,
Medium = _ref.Medium,
Small = _ref.Small,
Mini = _ref.Mini;
_classCallCheck(this, Artwork);
this.Full = Full;
this.Large = Large;
this.Medium = Medium;
this.Small = Small;
this.Mini = Mini;
}
_createClass(Artwork, [{
key: "equals",