Greasy Fork is available in English.

Coral Isle Invitation Dialog Extension

Erweitert den Einladen Dialog von Coral Isle um "Zeige Profil"

  1. // ==UserScript==
  2. // @name Coral Isle Invitation Dialog Extension
  3. // @namespace http://blank.org/
  4. // @version 1.3.3
  5. // @description Erweitert den Einladen Dialog von Coral Isle um "Zeige Profil"
  6. // @author k5x
  7. // @match https://apps.facebook.com/coral-isle/*
  8. // @match https://apps.facebook.com/coral-isle
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
  10. // @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_addStyle
  13. // @run-at document-end
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var name = "Coral Isle Invitation Dialog Extension";
  19. var version="1.3.2";
  20. console.log("script start: Coral Isle Invitation Dialog Extension");
  21.  
  22. var idPrefix=Math.floor(Math.random() * (99999999 - 10000000 + 1)) + 10000000;
  23. var canConnect=false;
  24. var CurrentUser = {};
  25. var DisplayedUser ={};
  26. var Settings = {};
  27. var lastId=0;
  28. function nextId(){lastId++;return idPrefix+"_"+lastId;}
  29. function escapeMatch(s) {return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');}
  30. function getProfileUrlPart(href) {
  31. var n=null;
  32. if(href.contains("profile.php")) n = href.match(/(facebook\.com\/)(profile\.php\?id=\d+)&?/)[2];
  33. else n=href.match(/(facebook\.com\/)([^?]*)/)[2];
  34. // console.log(n);
  35. return n;
  36. }
  37. function urlMatch(url,matches){
  38. for(var i=0;i<matches.length;i++){
  39. var match=matches[i];
  40. var pattern=escapeMatch(match.replace(/\*/g,'~STAR~'));
  41. pattern="^"+pattern.replace(/~STAR~/g,'.*?')+"$";
  42. var regexp=new RegExp(pattern,'i');
  43. if(regexp.test(url)) return true;
  44. }
  45. return false;
  46. }
  47. function getIdFromDataHovercard(elmt){
  48. var data=elmt.getAttribute('data-hovercard');
  49. if(data===null) {
  50. return null;
  51. }
  52. var id=data.match(/(id=)(\d+)/)[2];
  53. return id;
  54. }
  55. CurrentUser = {
  56. _name:"CurrentUser",
  57. id:null,
  58. link:null,
  59. profileName:null,
  60. displayName:null,
  61. fullName:null,
  62. token:null,
  63. updateFromTimelineProfile:function(){
  64. var me=CurrentUser;
  65. var $span=$("#fb-timeline-cover-name");
  66. var a=$span[0].parentElement;
  67. me.link = $(a).attr("href");
  68. me.fullName = $span.text();
  69. me.profileName = getProfileUrlPart(me.link);
  70. },
  71. updateFromBlueBar:function(){
  72. var me=CurrentUser;
  73. var selector1="a[data-testid='blue_bar_profile_link']";
  74. var selector2="a._2s25";
  75. var selector=null;
  76. var elmt= $(selector1)[0];
  77. if(elmt!==undefined) selector=selector1;
  78. else selector=selector2;
  79. me.link = $(selector).attr("href");
  80. me.id = $(selector+" img").attr("id").match(/\d+$/)[0];
  81. me.displayName = $(selector).text();
  82. me.profileName = getProfileUrlPart(me.link);
  83. },
  84. init:function() {
  85. var me=CurrentUser;
  86. me.updateFromBlueBar();
  87. }
  88. };
  89. var CiInvitationDialog={
  90. _name:"CiInvitationDialog",
  91. dialogFound:false,
  92. neighborId:null,
  93. neighborName:null,
  94. senderName:null,
  95. senderId:null,
  96. canConnect:true,
  97. openProfile:function() {
  98. console.log("openProfile");
  99. var me=CiInvitationDialog;
  100. window.open("https://www.facebook.com/profile.php?id="+me.neighborId,"_blank");
  101. document.getElementById("platformDialogForm").elements["__CANCEL__"][0].click();
  102. },
  103. tick: function () {
  104. var me=CiInvitationDialog;
  105. var form=document.getElementById("platformDialogForm");
  106. if(form!==null && me.dialogFound===false) {
  107. me.dialogFound=true;
  108. var elements=form.getElementsByClassName("uiTokenText");
  109. var span=elements[0];
  110. var td=span.parentElement.parentElement.parentElement;
  111.  
  112. $(form).append(`<div style="margin:4px">Diese Seite wurde erweitert mit <a href="#" target="_blank">Coral Isle Invitation Dialog Extension</a><div>`);
  113. $(".uiOverlayFooter").append(`<button type="button" id="openProfile" class="_42ft _4jy0 layerConfirm _1flv _51_n autofocus uiOverlayButton _4jy3 _4jy1 selected _51sy" style="position: absolute;left: 95px; background:green">Zeige Profil</button>`);
  114. $("#openProfile")[0].addEventListener('click',me.openProfile, false);
  115. me.neighborId=form.elements.to.value;
  116. setTimeout(me.tick,1000);
  117. return;
  118. }
  119. if(form===null && me.dialogFound===true) {
  120. me.dialogFound=false;
  121. }
  122. setTimeout(me.tick,1000);
  123. },
  124. onPageLoad:function(isAjax){
  125. console.log("CiInvitationDialog.onPageLoad(isAjax:"+isAjax+")");
  126. var me=CiInvitationDialog;
  127. if(!isAjax) {
  128. setTimeout(me.tick,3000);
  129. }
  130. }
  131. };
  132. console.log("location:", document.location.href);
  133. function onPageLoad(isAjax) {
  134. if(urlMatch(document.location.href,["https://apps.facebook.com/coral-isle/*","https://apps.facebook.com/coral-isle"])){
  135. CiInvitationDialog.onPageLoad(isAjax);
  136. }
  137. }
  138. var PageMonitor = {
  139. _name:"PageMonitor",
  140. count:0,
  141. onPageLoad:function(){},
  142. poll: function (me) {
  143. var href=document.location.href;
  144. if(!$("body").hasClass("PageMonitor")){
  145. $("body").addClass("PageMonitor");
  146. me.count++;
  147. console.log("Page load detected",href);
  148. setTimeout(function(){me.onPageLoad(me.count>1);},500);
  149. }
  150. },
  151. init: function(onPageLoad){
  152. var me=PageMonitor;
  153. me.onPageLoad=onPageLoad;
  154. setInterval(function(){me.poll(me);},100);
  155. }
  156. };
  157. function waitUserLoaded(){
  158. var elmt= $("a[data-testid='blue_bar_profile_link']")[0];
  159. if(elmt===undefined) elmt= $("a._2s25")[0];
  160. if(elmt===undefined) {
  161. setTimeout(waitUserLoaded,100);
  162. return;
  163. }
  164. CurrentUser.init();
  165. PageMonitor.init(onPageLoad);
  166. }
  167. waitUserLoaded();
  168. console.log("script initialized.");
  169. })();