Skip to content

Instantly share code, notes, and snippets.

@Jeremie-Chauvel
Last active March 31, 2020 08:09
Show Gist options
  • Select an option

  • Save Jeremie-Chauvel/935721aeab824c35a98ae1f6ac4fe440 to your computer and use it in GitHub Desktop.

Select an option

Save Jeremie-Chauvel/935721aeab824c35a98ae1f6ac4fe440 to your computer and use it in GitHub Desktop.
Utilities to export as markdown your funretro board and clean it

Utilities to export as markdown your funretro board and clean it

Those two bookmarklet allows you to export the content of your funretro board as markdown and empty your board.

Bookmarklet version (non-tech friendly)

To use them simply create a new bookmark and copy past the code in the url field. Then you only need to click on the bookmark to execute the script.

export

javascript: !function(){const e=window.location.pathname.split("/")[3],t=e=>{let t,n="";Object.values(e).sort((e,t)=>e.type.id-t.type.id).map(e=>{t!==e.type.id&&(t=e.type.id,n+=`\n###Column ${e.type.id}:\n`),cardContent=e.text+` **+${(e=>e.votes?Object.values(e.votes).reduce((e,t)=>e+t):0)(e)}**`,n+=`- ${cardContent}\n`}),(e=>{const t=document.createElement("textarea"),n=document.getSelection();t.textContent=e,document.body.appendChild(t),n.removeAllRanges(),t.select(),document.execCommand("copy"),n.removeAllRanges(),document.body.removeChild(t)})(n)};(async()=>{t(await(async()=>(await firebase.database().ref(`/messages/${e}/`).once("value")).val())()),console.log("Card contents are in your clipboard")})()}();

clean

javascript: !function(){const a=window.location.pathname.split("/")[3],e=e=>{Object.keys(e).forEach(e=>{(async e=>{await firebase.database().ref(`/messages/${a}/${e}`).remove()})(e)})};(async()=>{e(await(async()=>(await firebase.database().ref(`/messages/${a}/`).once("value")).val())())})()}();

unuglyfied versions

export

javascript: (function() {
  const BOARD_ID = window.location.pathname.split('/')[3],
    copy = text => {
      const node = document.createElement('textarea');
      const selection = document.getSelection();

      node.textContent = text;
      document.body.appendChild(node);

      selection.removeAllRanges();
      node.select();
      document.execCommand('copy');

      selection.removeAllRanges();
      document.body.removeChild(node);
    },
    getCards = async () => {
      return (
        await firebase
          .database()
          .ref(`/messages/${BOARD_ID}/`)
          .once('value')
      ).val();
    },
    computeCardVotes = card =>
      card.votes
        ? Object.values(card.votes).reduce(
            (accumulator, currentValue) => accumulator + currentValue
          )
        : 0,
    copyMessages = cards => {
      let exportedText = '';
      let columnType;
      Object.values(cards)
        .sort((firstItem, secondItem) => firstItem.type.id - secondItem.type.id)
        .map(card => {
          if (columnType !== card.type.id) {
            columnType = card.type.id;
            exportedText += `\n###Column ${card.type.id}:\n`;
          }
          cardContent = card.text + ` **+${computeCardVotes(card)}**`;
          exportedText += `- ${cardContent}\n`;
        });
      copy(exportedText);
    },
    runScript = async () => {
      copyMessages(await getCards());
      console.log('Card contents are in your clipboard');
    };
  runScript();
})();

clean

javascript: (function() {
  const BOARD_ID = window.location.pathname.split('/')[3],
    getMessages = async () => {
      return (
        await firebase
          .database()
          .ref(`/messages/${BOARD_ID}/`)
          .once('value')
      ).val();
    },
    removeMessageById = async cardId => {
      await firebase
        .database()
        .ref(`/messages/${BOARD_ID}/${cardId}`)
        .remove();
    },
    removeMessages = cards => {
      Object.keys(cards).forEach(cardId => {
        removeMessageById(cardId);
      });
    },
    runScript = async () => {
      removeMessages(await getMessages());
    };
  runScript();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment