From d94b936b818ac61e606b14cf9eb9505427e82b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9A=D1=83=D1=86=D1=8B=D0=BB=D0=BB=D0=BE?= Date: Sat, 12 Mar 2016 07:34:01 +0300 Subject: [PATCH] :arrow_up: @v1.0.0 --- dist/background.js | 117 +++++++- dist/content.js | 598 ++++++++++++++++++++++++++++++++----- dist/manifest.json | 14 +- dist/static/css/single.css | 43 --- dist/static/img/save.png | Bin 1012 -> 0 bytes manifest.json | 10 +- package.json | 2 +- 7 files changed, 643 insertions(+), 141 deletions(-) delete mode 100755 dist/static/css/single.css delete mode 100755 dist/static/img/save.png diff --git a/dist/background.js b/dist/background.js index 19e7fb2..ebfe8e6 100755 --- a/dist/background.js +++ b/dist/background.js @@ -1,7 +1,112 @@ -'use strict'; +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; -chrome.runtime.onMessage.addListener(function (msg) { - document.body.innerHTML = msg; - document.body.firstChild.click(); - document.body.innerHTML = ''; -}); \ No newline at end of file +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var _utils = __webpack_require__(1); + + (0, _utils.listen)('save', ({ artist, title, url }) => { + const link = document.createElement('a'); + link.href = url; + link.download = `${ artist } - ${ title }`; + document.body.appendChild(link); + link.click(); + document.body.innerHTML = ''; + }); + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.send = send; + exports.listen = listen; + exports.injectFunction = injectFunction; + function send(type, data, callback = () => {}) { + chrome.runtime.sendMessage(chrome.runtime.id, { type, data }, null, callback); + } + + const handlers = {}; + + chrome.runtime.onMessage.addListener(({ type, data }, ...rest) => { + if (typeof handlers[type] === 'function') { + handlers[type](data, ...rest); + } + }); + + document.body.addEventListener(chrome.runtime.id, ({ detail: { type, data } }) => { + if (typeof handlers[type] === 'function') { + handlers[type](data, ...rest); + } + + send(type, data); + }, false); + + function listen(type, handler) { + handlers[type] = handler; + } + + const injectedUtils = ` + { + extensionId: '${ chrome.runtime.id }', + send: ${ function (type, data) { + document.body.dispatchEvent(new CustomEvent(this.extensionId, { detail: { type, data } })); + } } + } + `; + + function injectFunction(func) { + const script = document.createElement('script'); + script.text = `(${ func })(${ injectedUtils })`; + document.body.appendChild(script); + } + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/dist/content.js b/dist/content.js index 0384885..a474e96 100755 --- a/dist/content.js +++ b/dist/content.js @@ -1,81 +1,517 @@ -'use strict'; - -document.body.addEventListener(chrome.runtime.id, function (e) { - return chrome.runtime.sendMessage(null, e.detail); -}, false); - -function executeInBody(func) { - const src = document.createElement('script'); - src.text = `(${ func.toString() })('${ chrome.runtime.id }')`; - document.querySelector('body').appendChild(src); -} - -executeInBody(function (extensionId) { - 'use strict'; - - function showTip() { - Audio.rowActive(this, 'Сохранить аудиозапись', [9, 5, 0]); - } - - function hideTip() { - Audio.rowInactive(this); - } - - function sendMessage(message) { - const event = new CustomEvent(extensionId, { detail: message }); - document.body.dispatchEvent(event); - } - - function save(e) { - e.stopPropagation(); - e.preventDefault(); - sendMessage(this.parentNode.innerHTML); - } - - function addSaver(audio) { - if (audio.querySelector('.audio_save')) { - return; - } - - const url = audio.querySelector('input').value, - titleEl = audio.querySelector('.title_wrap'), - artist = titleEl.querySelector('a').textContent.trim(), - title = titleEl.querySelector('.title').textContent.trim(), - fullTitle = `${ artist } - ${ title }`, - wrapper = document.createElement('div'); - - wrapper.className = 'audio_save_wrap fl_r'; - wrapper.addEventListener('mouseover', showTip, false); - wrapper.addEventListener('mouseout', hideTip, false); - - const saver = document.createElement('a'); - saver.setAttribute('download', `${ fullTitle }.mp3`); - saver.className = 'audio_save'; - saver.href = url; - saver.addEventListener('click', save, false); - - wrapper.appendChild(saver); - audio.querySelector('.actions').appendChild(wrapper); - } - - const observer = new MutationObserver(function (records) { - for (let record of records) { - for (let i = 0; i !== record.addedNodes.length; ++i) { - const node = record.addedNodes[i]; - if (node.nodeType === Element.ELEMENT_NODE && node.classList.contains('audio')) { - addSaver(node); - } else if (typeof node.querySelectorAll === 'function') { - const nodes = [].concat.apply([], node.querySelectorAll('.audio')); - nodes.forEach(addSaver); - } - } - } - }); - - observer.observe(document.body, { childList: true, subtree: true }); - - if (location.pathname.indexOf('/audio') === 0) { - const audios = [].concat.apply([], document.querySelectorAll('.audio')); - audios.forEach(addSaver); - } -}); \ No newline at end of file +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + __webpack_require__(2); + + var _utils = __webpack_require__(1); + + (0, _utils.injectFunction)(utils => { + function showTip() { + Audio.rowActive(this, 'Сохранить аудиозапись', [9, 5, 0]); + } + + function hideTip() { + Audio.rowInactive(this); + } + + function addSaver(audio) { + if (audio.querySelector('.audio_save')) { + return; + } + + const url = audio.querySelector('input').value, + titleEl = audio.querySelector('.title_wrap'), + artist = titleEl.querySelector('a').textContent.trim(), + title = titleEl.querySelector('.title').textContent.trim(), + wrapper = document.createElement('div'); + + wrapper.className = 'audio_save_wrap fl_r'; + wrapper.addEventListener('mouseover', showTip, false); + wrapper.addEventListener('mouseout', hideTip, false); + + const saver = document.createElement('div'); + saver.className = 'audio_save'; + saver.addEventListener('click', e => { + e.stopPropagation(); + utils.send('save', { artist, title, url }); + }, false); + + wrapper.appendChild(saver); + audio.querySelector('.actions').appendChild(wrapper); + } + + const observer = new MutationObserver(records => { + for (let record of records) { + for (let i = 0; i !== record.addedNodes.length; ++i) { + const node = record.addedNodes[i]; + if (node.nodeType === Element.ELEMENT_NODE && node.classList.contains('audio')) { + addSaver(node); + } else if (typeof node.querySelectorAll === 'function') { + const nodes = [].concat.apply([], node.querySelectorAll('.audio')); + nodes.forEach(addSaver); + } + } + } + }); + + observer.observe(document.body, { childList: true, subtree: true }); + + if (location.pathname.indexOf('/audio') === 0) { + const audios = [].concat.apply([], document.querySelectorAll('.audio')); + audios.forEach(addSaver); + } + }); + +/***/ }, +/* 1 */ +/***/ function(module, exports) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.send = send; + exports.listen = listen; + exports.injectFunction = injectFunction; + function send(type, data, callback = () => {}) { + chrome.runtime.sendMessage(chrome.runtime.id, { type, data }, null, callback); + } + + const handlers = {}; + + chrome.runtime.onMessage.addListener(({ type, data }, ...rest) => { + if (typeof handlers[type] === 'function') { + handlers[type](data, ...rest); + } + }); + + document.body.addEventListener(chrome.runtime.id, ({ detail: { type, data } }) => { + if (typeof handlers[type] === 'function') { + handlers[type](data, ...rest); + } + + send(type, data); + }, false); + + function listen(type, handler) { + handlers[type] = handler; + } + + const injectedUtils = ` + { + extensionId: '${ chrome.runtime.id }', + send: ${ function (type, data) { + document.body.dispatchEvent(new CustomEvent(this.extensionId, { detail: { type, data } })); + } } + } + `; + + function injectFunction(func) { + const script = document.createElement('script'); + script.text = `(${ func })(${ injectedUtils })`; + document.body.appendChild(script); + } + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + // style-loader: Adds some css to the DOM by adding a