Last active
October 24, 2019 03:56
-
-
Save Pmmlabs/c5d6a4f7a43545c96719 to your computer and use it in GitHub Desktop.
Плагин для VkOpt, добавляющий функцию точного поиска по аудиозаписям
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id exactsearch@vkopt | |
// @name Точный поиск для VkOpt | |
// @version 1.0 | |
// @namespace https://greasyfork.org/users/23 | |
// @author Pmmlabs@github | |
// @description Плагин для VkOpt, добавляющий функцию точного поиска по аудиозаписям | |
// @include *vk.com* | |
// @run-at document-end | |
// @noframes | |
// @grant none | |
// ==/UserScript== | |
if (!window.vkopt_plugins) vkopt_plugins = {}; | |
(function () { | |
var PLUGIN_ID = 'ExactAudioSearch'; | |
vkopt_plugins[PLUGIN_ID] = { | |
Name: 'Exact Audio Search', | |
query: '', // поисковый запрос | |
performer: 0, // поиск по исполнителю | |
onLocation: function (nav_obj, cur_module_name) { | |
if (cur_module_name == 'audio') | |
this.UI(); | |
}, | |
UI: function () { | |
if (!ge('audioExactSearch')) { // создание галочки "искать в точности" | |
var parent = ge('pad_album_filters') || ge('album_filters'); | |
var el = vkCe('div', {'class': 'audio_filter'}, '<div id="audioExactSearch" class="label"></div>'); | |
parent.insertBefore(el, domFC(parent)); | |
stManager.add('ui_controls.js', function () { | |
new Checkbox(ge('audioExactSearch'), { | |
checked: false, | |
label: 'Точный поиск' | |
}); | |
}); | |
} | |
}, | |
filter: function (div) { // чистка контейнера с аудиозаписями div от лишних аудио | |
var audios = geByClass('audio', div); | |
for (var i in audios) { | |
var performer = geByTag('b', audios[i])[0].textContent.toLowerCase().trim(); | |
var title = geByClass('title', audios[i])[0].textContent.toLowerCase().trim(); | |
if (vkopt_plugins[PLUGIN_ID].performer == 1 && performer != vkopt_plugins[PLUGIN_ID].query | |
|| vkopt_plugins[PLUGIN_ID].performer == 0 && title != vkopt_plugins[PLUGIN_ID].query && performer + ' - ' + title != vkopt_plugins[PLUGIN_ID].query) | |
re(audios[i]); | |
} | |
}, | |
onResponseAnswer: function (answer, url, params) { // Обработка поискового запроса | |
if (val(ge('audioExactSearch')) && url == '/audio' && params.act == 'search') { | |
this.performer = params.performer; // поиск по исполнителю | |
this.query = params.q.toLowerCase().trim(); // поисковый запрос (регистронезависимый) | |
answer[0] = vkModAsNode(answer[0], this.filter); | |
answer[1] = vkModAsNode(answer[1], this.filter); | |
} else if (url == '/pads.php' && params.pad_id == 'mus') | |
setTimeout(vkopt_plugins[PLUGIN_ID].UI, 1); | |
} | |
}; | |
if (window.vkopt_ready) vkopt_plugin_run(PLUGIN_ID); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment