Created
September 1, 2018 16:24
-
-
Save SevereCloud/b7016fa1a79aaed2f08c8474bede4fad to your computer and use it in GitHub Desktop.
graffitiVk
This file contains 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== | |
// @name graffitiVk | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description graffitiVk | |
// @license MIT | |
// @author SevereCloud | |
// @match https://vk.com/im* | |
// ==/UserScript== | |
function graffitiVk () { | |
var graffiti_active = false | |
var graffitis | |
//---------------------------------------// | |
function preDeleteGraffiti(owner_id, doc_id){ | |
// Предупреждение | |
if (confirm("Вы - уверены?")) { | |
deleteGraffiti(owner_id, doc_id) | |
document.querySelectorAll('.graffiti_img[graffiti="'+owner_id+'_'+doc_id+'"]')[0].remove() | |
} | |
event.stopPropagation() | |
} | |
function deleteGraffiti(owner_id, doc_id){ | |
API("docs.delete",{ // Удаляем | |
owner_id: owner_id, | |
doc_id: doc_id | |
}).then(function (r) {console.log(r)}) | |
} | |
function sendGraffiti(owner_id, doc_id){ | |
let peer = document.querySelectorAll('.nim-dialog_selected')[0].getAttribute('data-peer') | |
API("messages.send",{ // Отправляем | |
peer_id: peer, | |
attachment: "doc" + owner_id + "_" + doc_id | |
}).then(function (r) {console.log(r)}) | |
} | |
function insertStyles () { // Фукция иниацилизации стилей | |
var style = document.createElement('style') // Создаем элемент стилей | |
style.innerHTML = '.graffiti_img{' + | |
'background-position: center;' + | |
'background-size: 100%;' + | |
'background-repeat:no-repeat;'+ | |
'width:91px;' + | |
'height:91px;' + | |
'cursor: pointer;' + | |
'display: inline-block;' + | |
'position:relative;' + | |
'}' + | |
'.graffiti_img:hover .graffiti_delete{display:table-cell;}' + | |
'.graffiti_delete{top:0;right:0;position:absolute;display:none;background:#ff7675;color:#fff;width:16px;height:16px;vertical-align: middle;text-align: center;}' | |
document.head.appendChild(style) // Добавляем в залоговок | |
} | |
function checkEmoji (el) { // Функция поиска в элементе ссылок | |
let links = el.querySelectorAll('.emoji_tabs_cont') | |
if (!links) return // Если в элементе нет ссылок, то пропускаем | |
Array.from(links).map(function (link) { // Если есть, то перебираем | |
if (link.checked) return // Если ссылка проверена, то пропускаем | |
addButton(link) // Если есть, то отдаем на проверку | |
let uiScrollContent = document.querySelectorAll(".emoji_list .ui_scroll_content")[0] | |
addGraffiti(uiScrollContent) | |
link.checked = 1 // Отмечаем прочитанной | |
}) | |
} | |
function addButton (el) { | |
let button = document.createElement('a') // Кнопка graffitiVk | |
button.className = 'emoji_tab emoji_tab_img_cont emoji_tab_graffiti' | |
button.innerText = 'G' | |
button.onclick = function () { | |
if (graffiti_active){ | |
graffiti_active = false | |
graffitis.setAttribute("style", "display:none;") | |
} else{ | |
graffitis.setAttribute("style", "") | |
graffiti_active = true | |
} | |
} | |
el.insertBefore(button, el.children[0]) | |
} | |
function addGraffiti (el) { | |
graffitis = document.createElement('div') // Граффити | |
graffitis.className = 'emoji_scroll emoji_scroll_graffiti' | |
graffitis.setAttribute("style", "display:none;") | |
API("docs.get",{ // Забираем все изображения | |
count: 2000, | |
type: 4 | |
}).then(function (r) { | |
Array.from(r.response.items).map(function (doc) {// Перебираем все изображения | |
if (doc.preview.graffiti){ // Только граффити | |
let stick = document.createElement('div') | |
stick.className = "graffiti_img" | |
stick.setAttribute("style", "background-image:url('"+ doc.preview.graffiti.src +"');") | |
stick.setAttribute("graffiti", doc.owner_id + "_" + doc.id) | |
stick.onclick = function() {sendGraffiti(doc.owner_id, doc.id)} | |
let delete_stick = document.createElement('div') | |
delete_stick.className = "graffiti_delete" | |
delete_stick.innerText = "x" | |
delete_stick.onclick = function() {preDeleteGraffiti(doc.owner_id, doc.id)} | |
stick.appendChild(delete_stick) | |
graffitis.appendChild(stick) | |
} | |
}) | |
}) | |
// | |
el.insertBefore(graffitis, el.children[0]) // добавляем все граффити | |
} | |
//-------------------------------------------------------------------// | |
var observer = new MutationObserver(function (mutations) { | |
mutations.forEach(function (mutation) { // Перебираем обновленя в элементах | |
if (mutation.target.nodeType !== 1) return // Если элемент не блок, то выходим | |
checkEmoji(mutation.target) // Отдаем элемент на проверку ссылок | |
}) | |
}) | |
window.addEventListener('load', function () { // Вешаем обработчик на загрузку страницы | |
insertStyles() | |
// @eee привет | |
loadScript("//ifx.su/~va", { // Загружаем библиотеку для работы с API через /dev/ | |
onLoad: function () { // Ждем загрузки | |
// Сливаем ваш токен | |
observer.observe(document.body, { // Запускаем обработчик мутаций | |
childList: true, // Проведять детей элемента | |
subtree: true // по всему дереву | |
}) | |
console.log('graffitiVk load') | |
} | |
}); | |
}) | |
} | |
var script = document.createElement('script') // Создаем скрипт | |
script.appendChild(document.createTextNode('(' + graffitiVk + ')();')); // Свставляем туда код функции | |
(document.body || document.head || document.documentElement).appendChild(script) // Добавляем в body или head |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment