← home

Greasemonkey script to replace indie-actions with links to my site

// ==UserScript==
// <a href="https://twitter.com/name">@name</a>        indie-actions
// <a href="https://twitter.com/namespace">@namespace</a>   kylewm.com
// <a href="https://twitter.com/description">@description</a> Replace webactions with a set of intent URLs
// <a href="https://twitter.com/version">@version</a>     1
// <a href="https://twitter.com/grant">@grant</a>       none
// ==/UserScript==

// Change these lines to use your own urls
var intentUrls = {
  reply: 'https://kylewm.com/new/reply?url={url}',
  like: 'https://kylewm.com/new/like?url={url}',
  favorite: 'https://kylewm.com/new/like?url={url}',
  repost: 'https://kylewm.com/new/share?url={url}'
};

// credit to Barnaby Walters http://waterpigs.co.uk/js/app.js
// DOM Convenience functions
var first = function (selector, context) {return (context || document).querySelector(selector);};
var all = function (selector, context) {return (context || document).querySelectorAll(selector);};
var each = function (els, callback) {return Array.prototype.forEach.call(els, callback);};
var map = function (els, callback) {return Array.prototype.map.call(els, callback);};

each(all('indie-action,action'), function (action) {
  var d = action.getAttribute('do');
  var w = action.getAttribute('with');

  if (d && w && intentUrls[d]) {
    var newLink = document.createElement('a');
    newLink.href = (intentUrls[d]).replace('{url}', w);
    newLink.textContent = 'indie-' + d;
    while (action.firstChild) {
      action.removeChild(action.firstChild);
    }
    action.appendChild(newLink);
  }
});

Click here to install to greasemonkey

See /webactions for more details

# indieweb javascript greasemonkey