instagram in twitter

Display instgram picture in twitter

  1. // ==UserScript==
  2. // @id xuboying
  3. // @name instagram in twitter
  4. // @version 0.0.1
  5. // @description Display instgram picture in twitter
  6. // @include https://twitter.com/*
  7. // @grant GM_xmlhttpRequest
  8. // @namespace https://gf.qytechs.cn/users/50045
  9. // ==/UserScript==
  10. // set security.csp.enable = false in firefox
  11. // support: https://stackoverflow.com/questions/5890110/greasemonkey-script-to-work-on-dynamically-loaded-posts-on-facebook
  12. if (window.top != window.self) //don't run on frames or iframes
  13. return;
  14. function foo() {
  15. var elements = document.querySelectorAll('a');
  16. var re = new RegExp('instagram.com');
  17. for (i = 0; i < elements.length; i++) {
  18. var url = elements[i].getAttribute('data-expanded-url');
  19. if (url != null) {
  20. if (url.match(re)) {
  21. GM_xmlhttpRequest({
  22. method: 'GET',
  23. url: url,
  24. onload:
  25. function (j) {
  26. return function (response) {
  27. if (response.status != 200) {
  28. return;
  29. }
  30. if (response.responseText == '') {
  31. return;
  32. }
  33. resp = response.responseText;
  34. var imgsrc = resp.match(/"display_src":\s*"(.*?)"/) [1];
  35. imgsrc = imgsrc.replace(/\\/g, '');
  36. if (!elements[j].parentNode.innerHTML.match(/replaced/)) {
  37. elements[j].parentNode.innerHTML += '<div id="replaced"><img width = "100%" src=\'' + imgsrc + '\'/></div>';
  38. } //console.log(img);
  39.  
  40. }
  41. }(i)
  42. }
  43. );
  44. }
  45. }
  46. }
  47. }
  48. foo();
  49. var PostsChangedByAJAX_Timer = '';
  50. //--- Change this next line to find the correct element; sample shown.
  51. var PostContainerNode = document.getElementById('timeline');
  52. //var PostContainerNode = document.getElementsByClassName('stream');
  53. PostContainerNode.addEventListener('DOMSubtreeModified', PageBitHasLoaded, false);
  54. function PageBitHasLoaded(zEvent) {
  55. /*--- Set and reset a timer so that we run our code (LocalMain() ) only
  56. AFTER the last post -- in a batch -- is added. Adjust the time if needed, but
  57. half a second is a good all-round value.
  58. */
  59. if (typeof PostsChangedByAJAX_Timer == 'number')
  60. {
  61. clearTimeout(PostsChangedByAJAX_Timer);
  62. PostsChangedByAJAX_Timer = '';
  63. }
  64. PostsChangedByAJAX_Timer = setTimeout(function () {
  65. foo();
  66. }, 555);
  67. }

QingJ © 2025

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