Greasy Fork is available in English.

Remove TweetDeck Retweet Modal Dialog

Skips the "Retweet to your followers?" modal asking whether or not to quote tweet for TweetDeck

  1. // ==UserScript==
  2. // @name Remove TweetDeck Retweet Modal Dialog
  3. // @description Skips the "Retweet to your followers?" modal asking whether or not to quote tweet for TweetDeck
  4. // @namespace https://github.com/alexwh
  5. // @version 1.0
  6. // @match https://tweetdeck.twitter.com/*
  7. // ==/UserScript==
  8.  
  9. function patch() {
  10. // monkeypatch the displayTweet function that's called near the end of
  11. // initing the ActionDialog object. we need to call selectAccount first
  12. // since that's done after the displayTweet call, and we can't really
  13. // cleanly patch anything later. the original code calls, in order:
  14. // this.displayTweet(t)
  15. // this.accountSelector.$node.on(TD.components.AccountSelector.CHANGE, this._handleAccountSelectionChange.bind(this))
  16. // this.accountSelector.selectAccount(t.account)
  17. // this.setAndShowContainer((0, s.default) ('#actions-modal'))
  18. unsafeWindow.TD.components.ActionDialog.prototype.displayTweet = function(t) {
  19. this.accountSelector.selectAccount(t.account)
  20. this._retweet()
  21. }
  22.  
  23. // patch setAndShowContainer to not show if we're being called from the
  24. // retweet ActionDialog. two places call with the #actions-modal selector,
  25. // retweets, and lists. to not remove lists, check for the presence of the
  26. // this.$retweetButton variable also. the rest of the function after the
  27. // first line remains unchanged from the original
  28. unsafeWindow.TD.components.BaseModal.prototype.setAndShowContainer = function(e, t) {
  29. if (e.selector === "#actions-modal" && typeof this.$retweetButton !== 'undefined') { return; }
  30. 'boolean' != typeof t && (t = !0),
  31. t && e.empty(),
  32. e.append(this.$node).show(),
  33. this._checkIfTouchModal(e)
  34. }
  35. }
  36.  
  37. (function wait() {
  38. if (unsafeWindow.TD && unsafeWindow.TD.ready) {
  39. patch();
  40. } else {
  41. setTimeout(wait, 1000);
  42. }
  43. })();
  44.  
  45. // monologue below about my inexperience with js and userscripts, fumbling
  46. // around to try and get a good solution for this disgustingly easy problem
  47.  
  48. // this method ended up being the cleanest overall, as we maintain
  49. // tweetdeck's built in error handling, and don't need to reimplement a lot
  50. // of stuff.
  51.  
  52. // originally, I wanted to monkeypatch the
  53. // `TD.services.TwitterStatus.prototype.retweet` function to not create the
  54. // `TD.components.ActionDialog` object in the first place, and instead just
  55. // trigger the `uiRetweet` event directly which is later done by
  56. // `TD.components.ActionDialog`'s `_retweet` method.
  57. // this wasn't possible because jQuery listeners can't receive extra event
  58. // info from regular javascript event senders (which we need to send the
  59. // `tweetId` and `from` parameters). we also can't import jQuery in the
  60. // userscript and use $(document).trigger as they're namespaced separately
  61. // and the original tweetdeck jQuery instance never receives the event.
  62.  
  63. // after, I tried reimplementing the `sendRetweet` function that gets
  64. // called by the `uiRetweet` event in
  65. // `TD.services.TwitterStatus.prototype.retweet`. this also led to
  66. // reimplementing `makeTwitterApiCall` and
  67. // `TD.services.TwitterClient.prototype.makeTwitterCall`, and ended up
  68. // becoming too unwieldly when I had to delve into using tweetdeck's async
  69. // deferring techniques for undoing retweets (you need to search the
  70. // original tweet with the `include_my_retweet` parameter, then call
  71. // destroy on that id).
  72.  
  73. // there was also an attempt at creating a custom ActionDialog object that
  74. // would skip itself, but that didn't get very far either.
  75.  
  76. // the unfinished code for all is included below, in order:
  77.  
  78. // function custom_rt() {
  79. // let acct = TD.storage.accountController.getPostingAccounts()[0].privateState.key
  80. // let edetail = { id: "xxxx", from: [acct] }
  81. // let rtev = new CustomEvent('uiRetweet', edetail);
  82. // document.dispatchEvent(rtev)
  83. // }
  84.  
  85. // TD.services.TwitterStatus.prototype.retweet = function () {
  86. // if (!this.isRetweeted) {
  87. // // uiRetweet(id: this.id, from:this.account.getKey())
  88. // let url = TD.services.TwitterClient.prototype.API_BASE_URL + "statuses/retweet/:id.json".replace(':id', this.id)
  89. // params = {method: "POST",
  90. // handleSuccess: false,
  91. // handleError: false,
  92. // url: url,
  93. // account: this.account
  94. // }
  95. // TD.net.ajax.request(url, params)
  96. // this.setRetweeted(true)
  97. // }
  98. // else {
  99. // // uiUndoRetweet(tweetId: this.getMainTweet().id, from: this.account.getKey())
  100. // let search_url = TD.services.TwitterClient.prototype.API_BASE_URL + "statuses/show/:id.json?include_my_retweet=true".replace(':id', this.id)
  101. // let params = {method: "GET", include_my_retweet: true}
  102. // let search_resp = TD.net.ajax.request(search_url, params)
  103. // console.log(search_resp)
  104. // let rt_id = search_resp.results[0].data.current_user_retweet.id_str
  105. // // let rt_id = search_resp.results[0].data.retweeted_status.id_str
  106. // // var cb = new TD.core.defer.Deferred
  107.  
  108. // let del_url = TD.services.TwitterClient.prototype.API_BASE_URL + "statuses/destroy/:id.json".replace(':id', rt_id)
  109. // params = {method: "POST",
  110. // handleSuccess: false,
  111. // handleError: false,
  112. // url: del_url,
  113. // account: this.account
  114. // }
  115. // TD.net.ajax.request(del_url, params)
  116. // this.setRetweeted(false)
  117. // }
  118. // }
  119.  
  120. // var ad = new TD.components.ActionDialog({tweet: {tweet: {id: "xxx"}, accountSelector: new TD.components.AccountSelector, getMainUser: function() {return "yes"}},title: "yes"})