Fanfou Forward Without Mentioning Myself

饭否上转发消息时避免at到自己

  1. // ==UserScript==
  2. // @name Fanfou Forward Without Mentioning Myself
  3. // @version 1.0.5
  4. // @author HackMyBrain
  5. // @description 饭否上转发消息时避免at到自己
  6. // @include http://fanfou.com/*
  7. // @namespace https://gf.qytechs.cn/users/2844
  8. // ==/UserScript==
  9.  
  10.  
  11. (function (){
  12. var mylink = document.querySelector('#navigation ul > li:nth-of-type(2) > a'); //获取"我的空间"元素,用于后续判断消息中的超链接
  13. try{
  14. var fw_textarea = document.getElementById('PopupForm').getElementsByTagName('textarea')[0];
  15. } catch(err) {
  16. return;
  17. }
  18. var fwReplacer = function (e){
  19. if ( e.target.tagName.toLowerCase() === 'a' && e.target.className === 'repost' ){
  20. var text = e.target.getAttribute('text');
  21. var fw_nickname = text.match(/@\S+/)[0]; // 获取被直接转发的饭er的昵称
  22. var content = e.target.parentElement.parentElement.getElementsByClassName('content')[0];
  23. var context_text = ' ';
  24. var content_child;
  25. for(var i = 0; i < content.childNodes.length; i++){
  26. content_child = content.childNodes[i];
  27. if ( content_child.nodeType === 3 || content_child.tagName.toLowerCase() === 'strong' || content_child.className === 'former' || content_child.className === 'nickquery' || ( !!content_child.href && content_child.href.indexOf('http://fanfou.com/q/') === 0 ) ) {
  28. if ( content_child.className === 'former' && content_child.href === mylink.href ) { // 消息中at到自己的部分
  29. context_text += content_child.textContent + '\n';
  30. } else { // 普通文本、at不到的人、at得到的别人
  31. context_text += content_child.textContent;
  32. }
  33. } else if ( content_child.getAttribute('rel') === 'nofollow' ){ // 消息中夹带的超链接
  34. context_text += content_child.getAttribute('title');
  35. }
  36. }
  37. // context_text = context_text.replace(/^\x20{2}/, '\x20'); // 带有图片的消息, content_child 中的 text 节点开头有多余的空格(饭否本身的问题), 应去掉
  38. setTimeout(function(){
  39. if ( e.target.parentElement.querySelectorAll(".delete, a[href*='/photo.del/'][class='post_act']").length != 0 ) {
  40. //通过检测是否有删除按钮, 判断所直接转发的是否自己的消息. a[href*='/photo.del/'][class='post_act'] 是自己相册页面的删除按钮
  41. fw_textarea.value = ('转' + fw_nickname + '\n' + context_text).replace(/\n\x20/g,'\n');
  42. } else {
  43. fw_textarea.value = ('转' + fw_nickname + context_text).replace(/\n\x20/g,'\n');
  44. }
  45. },30);
  46. setTimeout(function(){fw_textarea.setSelectionRange(0,0)}, 60); // 光标定位到消息框开头
  47. }
  48. }
  49. document.addEventListener('click', fwReplacer, false);
  50. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址