Last active
August 19, 2022 06:51
-
-
Save Pmmlabs/3653dde2dd5b22510426 to your computer and use it in GitHub Desktop.
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 wallsearch@vkopt | |
// @name Wall Search by UID for 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 = 'wallSearch'; | |
vkopt_plugins[PLUGIN_ID] = { | |
Name: 'Search posts and comments at wall by user id', | |
el_id: 'vk_wall_search', | |
end: false, | |
totalWall: 0, | |
totalComments: 0, | |
query_id: 0, | |
step: 100, | |
currentPosts: null, | |
result:[], | |
onLocation: function (nav_obj, cur_module_name) { // при открытии страницы группы или паблика | |
if (!ge(this.el_id) && (cur_module_name == 'groups' || cur_module_name == 'public')) | |
this.UI(); | |
}, | |
UI: function () { // Добавление ссылки | |
var html = 'id пользователя: <input type="text" size="12" value="'+vk.id+'"/>' + | |
'<button class="flat_button" onclick="vkopt_plugins.' + PLUGIN_ID + '.start(val(this.previousElementSibling))">Старт</button> ' + | |
'<button class="flat_button" id="vk_prune" style="display: none;" onclick="vkopt_plugins.' + PLUGIN_ID + '.prune()">Удалить всё</button><br>' + | |
'<div id="vkWallSearchProgress1"></div><div id="vkWallSearchProgress2"></div><div id="vkWallSearchResult" class="wall_module"></div>'; | |
var a = vkCe('a', {id: this.el_id}, 'Поиск по автору'); | |
a.onclick = function () { | |
vkAlertBox('Поиск', html, function () { | |
vkopt_plugins[PLUGIN_ID].end = true; | |
}); | |
}; | |
var parent; | |
if (parent = ge('page_actions')) { | |
parent.appendChild(a); | |
} | |
else if (parent = (ge('unsubscribe') || ge('subscribe'))) { | |
parent.appendChild(vkCe('br')); | |
parent.appendChild(a); | |
} | |
}, | |
start: function (uid) { | |
if (!uid) uid = vk.id; | |
this.end = false; | |
this.query_id = uid; | |
this.runWall(0); | |
this.result=[]; | |
var fch; | |
while (fch = ge('vkWallSearchResult').firstChild) | |
re(fch); | |
show('vk_prune'); | |
}, | |
runWall: function (_offset) { | |
if (!this.end) dApi.call('wall.get', { | |
owner_id: cur.oid, | |
count: this.step, | |
offset: _offset | |
}, function (r, response) { | |
if (response) { | |
vkopt_plugins[PLUGIN_ID].totalWall = response.shift(); | |
if (response.length > 0) { | |
vkopt_plugins[PLUGIN_ID].currentPosts = response; | |
vkopt_plugins[PLUGIN_ID].processPosts(0, _offset, function () { | |
vkopt_plugins[PLUGIN_ID].runWall(_offset + vkopt_plugins[PLUGIN_ID].step) | |
}); | |
} | |
else | |
ge('vkWallSearchProgress1').innerHTML = ge('vkWallSearchProgress2').innerHTML = ''; | |
} else // retry | |
vkopt_plugins[PLUGIN_ID].runWall(_offset); | |
}); | |
}, | |
processPosts: function (i, wall_offset, callback) { | |
if (i < this.currentPosts.length) { | |
this.progress(wall_offset + i, this.totalWall, 1); | |
if (this.currentPosts[i].from_id == this.query_id) { | |
this.render(this.currentPosts[i]); | |
this.processPosts(i + 1, wall_offset, callback); | |
} | |
else if (this.currentPosts[i].comments && this.currentPosts[i].comments.count) | |
this.runComments(0, i, function () { | |
vkopt_plugins[PLUGIN_ID].processPosts(i + 1, wall_offset, callback); | |
}); | |
else | |
this.processPosts(i + 1, wall_offset, callback); | |
} else | |
callback(); | |
}, | |
runComments: function (_offset, post_i, callback) { | |
if (!this.end) dApi.call('wall.getComments', { | |
owner_id: this.currentPosts[post_i].to_id || cur.oid, | |
post_id: this.currentPosts[post_i].id, | |
need_likes: 0, | |
preview_length: 50, | |
count: this.step, | |
offset: _offset | |
}, function (r, response) { | |
if (response) { | |
vkopt_plugins[PLUGIN_ID].totalComments = response.shift(); | |
vkopt_plugins[PLUGIN_ID].progress(_offset, vkopt_plugins[PLUGIN_ID].totalComments, 2); | |
if (response.length > 0) { | |
for (var i in response) | |
if (response[i].from_id == vkopt_plugins[PLUGIN_ID].query_id) | |
vkopt_plugins[PLUGIN_ID].render(response[i], vkopt_plugins[PLUGIN_ID].currentPosts[post_i].id); | |
if (_offset + vkopt_plugins[PLUGIN_ID].step < vkopt_plugins[PLUGIN_ID].totalComments) | |
vkopt_plugins[PLUGIN_ID].runComments(_offset + vkopt_plugins[PLUGIN_ID].step, post_i, callback); | |
else | |
callback(); | |
} | |
else | |
callback(); | |
} else //retry | |
vkopt_plugins[PLUGIN_ID].runComments(_offset, post_i, callback); | |
}); | |
}, | |
render: function (post, post_id) { | |
var onclick = function () { | |
ajax.post('/wkview.php', { | |
act: 'show', | |
al: 1, | |
reply: post.cid || '', | |
w: 'wall' + cur.oid + '_' + (post.id || post_id) | |
}, | |
{ | |
onDone: function (a, html, obj) { | |
window.wkcur = obj; | |
vkAlertBox('Просмотр записи', html).setOptions({width: 660}); | |
animate(ge('box_layer_wrap'), {scrollTop: getXY('wpt'+pid)[1], transition: Fx.Transitions.easeInCirc}, 100); | |
} | |
}); | |
}; | |
var templateActions = '<div class="fl_r post_actions_wrap">\ | |
<div class="post_actions">\ | |
<div style="opacity: 0;" id="post_delete{pid}" class="post_delete_button fl_r"\ | |
onclick="cancelEvent(event);vkopt_plugins.' + PLUGIN_ID + '.deletePost(\'{pid}\',{is_comment});"\ | |
onmouseover="wall.activeDeletePost(\'{pid}\', \'Удалить запись\', \'post_delete\')"\ | |
onmouseout="wall.deactiveDeletePost(\'{pid}\', \'post_delete\')"></div>\ | |
</div>\ | |
</div>'; | |
var templateText = '<div class="wall_text">\ | |
<div class="wall_post_text">{text}</div>\ | |
</div>\ | |
<div class="reply_link_wrap sm" id="wpe_bottom{pid}">\ | |
<small><a href="/wall{pid}" target="_blank" onclick="return false;">{date}</a></small>\ | |
</div>'; | |
var pid = (post.to_id || cur.oid) + '_' + (post.cid || post.id || post_id); | |
var div = vkCe('div', { | |
'id': 'post' + pid, | |
'class': "post all", | |
'onmouseover': "wall.postOver('" + pid + "');", | |
'onmouseout': "wall.postOut('" + pid + "');" | |
}, (templateActions + templateText).replace(/\{pid\}/g, pid) | |
.replace('{date}', dateFormat(post.date * 1000, "dd.mm.yyyy")) | |
.replace(/\{text\}/g, post.text.replace(/\[[^\|]+\|([^\]]+)\]/g, '$1')) | |
.replace('{is_comment}', intval(!!post.cid))); | |
div.onclick = onclick; | |
ge('vkWallSearchResult').appendChild(div); | |
this.result.push({pid: pid, is_comment: intval(!!post.cid)}); | |
}, | |
progress: function (current, total, number) { // обновление прогрессбара | |
if (!total) total = 1; | |
var texts = ['Стена, %', 'Комментарии, %']; | |
ge('vkWallSearchProgress' + number).innerHTML = vkProgressBar(current, total, 380, texts[number-1]); | |
}, | |
deletePost: function (pid, is_comment, callback) { | |
wall.deactiveDeletePost(pid, 'post_delete'); | |
var op = pid.split('_'); | |
dApi.call('wall.delete' + (is_comment ? 'Comment' : ''), { | |
owner_id: op[0], | |
comment_id: op[1], | |
post_id: op[1] | |
}, function (r, response) { | |
if (response) re('post' + pid); | |
if (callback) callback(); | |
}); | |
}, | |
prune: function () { | |
if (vkopt_plugins[PLUGIN_ID].result.length) { | |
var post = vkopt_plugins[PLUGIN_ID].result.shift(); | |
var _callee = arguments.callee; | |
vkopt_plugins[PLUGIN_ID].deletePost(post.pid, post.is_comment, function(){setTimeout(_callee,300)}); | |
} | |
} | |
}; | |
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