Advertisement
stuppid_bot

Пишем в личку через репост из группы

May 25th, 2014
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @match http://vk.com/*
  3. // @match https://vk.com/*
  4. // @description Постим сообщения в личку через группу, чтобы их потом можно было удалить
  5. // ==/UserScript==
  6.  
  7. // УСТАНОВКА
  8. //
  9. // Сохраните текст скрипта в виде файла с именем %название%.user.js. Потом откройте в Хроме chrome://extensions, выберите расширения и перетащите туда файл. Вот и вся установка.
  10.  
  11. // вписываем id группы через которую будем постить
  12. GROUP_ID = 71985986;
  13.  
  14. function exec(func, args) {
  15.     args = args || '';
  16.     var scr = document.createElement('script');
  17.     scr.innerHTML = '(' + func + ')(' + args + ')';
  18.     document.head.appendChild(scr);
  19. }
  20.  
  21. if (this == top) {
  22.     var loc;
  23.     setInterval(function () {
  24.         var cur = location.pathname + location.search;
  25.  
  26.         if (loc != cur) {
  27.             loc = cur;
  28.             console.log('Адрес изменился: ' + loc);
  29.            
  30.             if (location.pathname == '/im' && location.search.indexOf('sel=') > -1 && !document.getElementById('pm_container')) {
  31.                 exec(function (group_id) {
  32.                     function getContent(url, cb) {
  33.                         var xhr = new XMLHttpRequest;
  34.                         xhr.open('GET', url);
  35.                         xhr.onload = function () {
  36.                             cb(xhr.responseText)
  37.                         }
  38.                         xhr.send();
  39.                     }
  40.  
  41.                     window.onCtrlEnter = function (evt) {
  42.                         if (evt.ctrlKey && (evt.keyCode == 0xA || event.keyCode == 0xD)) {
  43.                             ge('pm_send').onclick();
  44.                         }
  45.                     }
  46.  
  47.                     window.pm_send = function (post_hash) {
  48.                         var txt = val('pm_txt').trim();
  49.  
  50.                         if (txt == '') return;
  51.                         val('pm_txt', '');
  52.  
  53.                         ajax.post('/al_wall.php', {
  54.                             al: 1,
  55.                             official: 1,
  56.                             act: 'post',
  57.                             type: 'all',
  58.                             hash: post_hash,
  59.                             to_id: -group_id,
  60.                             Message: txt
  61.                         }, {
  62.                             onDone: function (data) {
  63.                                 // console.log(arguments);
  64.                                 var matches = data.match(/<div id="post([^"]+)/);
  65.                                 var entry = 'wall' + matches[1];
  66.                                 console.log(entry);
  67.  
  68.                                 getContent('/like.php?act=publish_box&al=1&object=' + entry, function (data) {
  69.                                     var matches = data.match(/imHash: '([^']+)/);
  70.  
  71.                                     ajax.post('/al_mail.php', {
  72.                                         // Message: '',
  73.                                         act: 'a_send',
  74.                                         ajax: 1,
  75.                                         al: 1,
  76.                                         chas: matches[1],
  77.                                         from: 'box',
  78.                                         media: entry,
  79.                                         // title: '',
  80.                                         to_ids: cur.peer
  81.                                     });
  82.                                 });
  83.                             }
  84.                         });
  85.                     }
  86.  
  87.                     getContent('/club' + group_id, function (data) {
  88.                         var matches = data.match(/"post_hash":"([^"]+)/);
  89.                         var A = document.getElementById('im_resizer_wrap');
  90.                         var B = document.createElement('div');
  91.                         B.id = 'pm_container';
  92.                         B.innerHTML = '<textarea id="pm_txt" style="width: 300px" onkeypress="onCtrlEnter(event)"></textarea>' +
  93.                                       '<button id="pm_send" onclick="pm_send(\'' + matches[1] + '\')">Репостим</button>'
  94.                         A.parentNode.insertBefore(B, A);
  95.                     });                
  96.                 }, GROUP_ID);
  97.             }
  98.         }
  99.     }, 10);
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement