diff options
-rw-r--r-- | exitter.el | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -563,7 +563,7 @@ Including ancestors and descendants, if any." .author.name .author.screen_name (exitter--relative-time-description .created_at) - .full_text + (exitter-replace-t-co-links .full_text) (if .quoted (format "\n\n----\n%s----" (replace-regexp-in-string @@ -699,6 +699,30 @@ TIME-STAMP is assumed to be in the past." (base64-encode-string (alist-get 'bs (bindat-unpack '((bs str 32)) (vconcat xs))))))) +(defun exitter-replace-t-co-links (text) + (with-temp-buffer + (insert text) + (goto-char (point-min)) + (while (re-search-forward "https://t.co" nil t) + (pcase-let* ((`(,beg . ,end) (bounds-of-thing-at-point 'url)) + (new-url (exitter-get-redirect-url + (buffer-substring-no-properties beg end)))) + (delete-region beg end) + (insert new-url))) + (buffer-string))) + +(defun exitter-get-redirect-url (url) + "Get redirect link of URL. + +Sends a HEAD request." + (let* ((url-request-method "HEAD") + (url-max-redirections 0) + (buffer (url-retrieve-synchronously url)) + (inhibit-message t)) + (with-current-buffer buffer + (goto-char (point-min)) + (when (re-search-forward "^Location: \\(.*\\)$" nil t) + (match-string 1))))) (require 'sha1) |