kernox / Mastodon Share Touch

// ==UserScript==
// @name         Mastodon Share Touch
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Key shortcut to share website on Mastodon
// @author       Hellexis
// @include      https://*
// @include      http://*
// @grant        GM_getValue
// @grant        GM_setValue
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  var key = 'F9';
  var instance = 'https://framapiaf.org';

  function init() {
    var savedToot = GM_getValue('MastoshareSavedToot');

    if (savedToot != '') {
      var tootBox = document.querySelector('.autosuggest-textarea__textarea');
      console.log(tootBox);

      if (tootBox != null) {
        tootBox.value = savedToot;
        //GM_setValue('MastoshareSavedToot', null);
      }

    }
  }

  function toot() {
    var title = document.title;
    var link = document.location;

    var toot = title + "\r\n" + link + "\r\n\r\n Shared from Mastodon Share Touch";

    GM_setValue('MastoshareSavedToot', toot);
    window.open(instance + '/web/getting-started');

  }

  document.addEventListener('keyup', function (e) {
    if (e.code == key) {
      toot();
    }
  });

  window.onload = function () {
    init();
  };
})();