From 00b212944c921d40f80adbb0d43347e8ac6aa7fb Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Sun, 28 Jan 2018 19:12:32 +0100
Subject: [PATCH] Implement top tier account bamboozle scheme

---
 Core/Handling/ContextMenuBase.cs  |  3 +-
 README.md                         |  2 +-
 Resources/Scripts/code.js         | 76 ++++++++++++++++++++++++-------
 Resources/Scripts/introduction.js |  8 +---
 4 files changed, 65 insertions(+), 24 deletions(-)

diff --git a/Core/Handling/ContextMenuBase.cs b/Core/Handling/ContextMenuBase.cs
index 369924a6..fef36f79 100644
--- a/Core/Handling/ContextMenuBase.cs
+++ b/Core/Handling/ContextMenuBase.cs
@@ -9,6 +9,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using TweetDuck.Core.Management;
+using TweetDuck.Core.Notification;
 using TweetDuck.Core.Other;
 
 namespace TweetDuck.Core.Handling{
@@ -81,7 +82,7 @@ public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser bro
                 model.AddItem(MenuSaveMedia, TextSave("video"));
                 model.AddSeparator();
             }
-            else if ((parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents) || hasTweetImage){
+            else if (((parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents) || hasTweetImage) && parameters.SourceUrl != TweetNotification.AppLogoLink){
                 model.AddItem(MenuViewImage, "View image in photo viewer");
                 model.AddItem(MenuOpenMediaUrl, TextOpen("image"));
                 model.AddItem(MenuCopyMediaUrl, TextCopy("image"));
diff --git a/README.md b/README.md
index e48aa848..63169ea7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # Support
 
-[Follow the developer](https://twitter.com/chylexmc) &nbsp;|&nbsp; [Support via PayPal](https://paypal.me/chylex) &nbsp;|&nbsp; [Support via Patreon](https://www.patreon.com/chylex)
+[Follow TweetDuck on Twitter](https://twitter.com/TryMyAwesomeApp) &nbsp;|&nbsp; [Support via PayPal](https://paypal.me/chylex) &nbsp;|&nbsp; [Support via Patreon](https://www.patreon.com/chylex)
 
 # Build Instructions
 
diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index c4312b6b..b441897c 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -446,21 +446,6 @@
     data.setData("text/html", `<a href="${url}">${url}</a>`);
   });
   
-  if (ensurePropertyExists(TD, "services", "TwitterUser", "prototype", "fromJSONObject")){
-    const prevFunc = TD.services.TwitterUser.prototype.fromJSONObject;
-    
-    TD.services.TwitterUser.prototype.fromJSONObject = function(){
-      let obj = prevFunc.apply(this, arguments);
-      let e = arguments[0].entities;
-      
-      if (e && e.url && e.url.urls && e.url.urls.length && e.url.urls[0].expanded_url){
-        obj.url = e.url.urls[0].expanded_url;
-      }
-      
-      return obj;
-    };
-  }
-  
   if (ensurePropertyExists(TD, "services", "TwitterMedia", "prototype", "fromMediaEntity")){
     const prevFunc = TD.services.TwitterMedia.prototype.fromMediaEntity;
     
@@ -480,6 +465,66 @@
     };
   }
   
+  //
+  // Block: Bypass t.co in user profiles and setup a top tier account bamboozle scheme.
+  //
+  (function(){
+    const realDisplayName = "TweetDuck";
+    const realAvatar = "https://ton.twimg.com/tduck/avatar";
+    const accountId = "957608948189880320";
+    
+    if (ensurePropertyExists(TD, "services", "TwitterUser", "prototype", "fromJSONObject")){
+      const prevFunc = TD.services.TwitterUser.prototype.fromJSONObject;
+      
+      TD.services.TwitterUser.prototype.fromJSONObject = function(){
+        let obj = prevFunc.apply(this, arguments);
+        let e = arguments[0].entities;
+
+        if (obj.id === accountId){
+          obj.name = realDisplayName;
+          obj.emojifiedName = realDisplayName;
+          obj.profileImageURL = realAvatar;
+          obj.url = "https://tweetduck.chylex.com";
+          
+          obj.entities.url.urls = [{
+            url: obj.url,
+            expanded_url: obj.url,
+            display_url: "tweetduck.chylex.com",
+            indices: [ 0, 23 ]
+          }];
+        }
+        else if (e && e.url && e.url.urls && e.url.urls.length && e.url.urls[0].expanded_url){
+          obj.url = e.url.urls[0].expanded_url;
+        }
+        
+        return obj;
+      };
+    }
+    
+    if (ensurePropertyExists(TD, "services", "TwitterClient", "prototype", "typeaheadSearch")){
+      const prevFunc = TD.services.TwitterClient.prototype.typeaheadSearch;
+      
+      TD.services.TwitterClient.prototype.typeaheadSearch = function(data, onSuccess, onError){
+        if (data.query && data.query.toLowerCase().endsWith("tweetduck")){
+          data.query = "TryMyAwesomeApp";
+        }
+        
+        return prevFunc.call(this, data, function(result){
+          for(let user of result.users){
+            if (user.id_str === accountId){
+              user.name = realDisplayName;
+              user.profile_image_url = realAvatar;
+              user.profile_image_url_https = realAvatar;
+              break;
+            }
+          }
+          
+          onSuccess.apply(this, arguments);
+        }, onError);
+      };
+    }
+  })();
+  
   //
   // Block: Include additional information in context menus.
   //
@@ -507,7 +552,6 @@
   //
   // Block: Hook into the notification sound effect.
   //
-  
   HTMLAudioElement.prototype.play = prependToFunction(HTMLAudioElement.prototype.play, function(){
     return $TDX.muteNotifications;
   });
diff --git a/Resources/Scripts/introduction.js b/Resources/Scripts/introduction.js
index 607c7345..5c93ea84 100644
--- a/Resources/Scripts/introduction.js
+++ b/Resources/Scripts/introduction.js
@@ -44,10 +44,6 @@
   margin-top: 15px;
 }
 
-#td-introduction-modal p:last-child {
-  margin-top: 18px;
-}
-
 #td-introduction-modal footer {
   padding: 10px 0;
 }
@@ -82,10 +78,10 @@
     <div class="mdl-inner">
       <div class="mdl-content">
         <p>Thank you for downloading TweetDuck!</p>
+        <p><a id="td-introduction-follow" href="#">Follow @TryMyAwesomeApp</a> for latest news and updates about the app.</p>
         <div class="main-menu"></div>
         <p><strong>Right-click anywhere</strong> or click <strong>Settings&nbsp;–&nbsp;TweetDuck</strong> in the left panel to open the main menu. You can also right-click links, tweets, images and videos, and desktop notifications to access their respective context menus.</p>
         <p>Click <strong>Show Guide</strong> to see awesome features TweetDuck offers, or view the guide later by going to <strong>About TweetDuck</strong> and clicking the help button on top.</p>
-        <p>Follow the developer <a id="td-introduction-follow" href="#">@chylexmc</a> for latest news &amp; updates about the app, and some occasional rants.</p>
       </div>
       <footer class="txt-right">
         <div class="anondata">
@@ -106,7 +102,7 @@
         onSuccess(tdUser);
       }
       else{
-        TD.controller.clients.getPreferredClient().getUsersByIds([ "572571847" ], users => onSuccess(users[0]), onError);
+        TD.controller.clients.getPreferredClient().getUsersByIds([ "957608948189880320" ], users => onSuccess(users[0]), onError);
       }
     };