Response Posts for Discussion Between Authors

Here is the code. The hashtag link is now clickable so you can quickly view responses and visitors can read how others have responded. Give it a try and let me know if it works for you. Instructions are included as comments in the code.

/* This code automatically inserts a hashtag below your post informing readers you are interested in response posts, and requesting they use a specific hashtag so you can find their response. There is also a mechanism to specify when you do not want a response.

Usage: Edit the "myResponseText" variable below to include your username or whatever text you want to display below posts.

When you don't want a response, type "responseno" anywhere in the post.

Tech note: By default, the text will be inserted above the first horizontal rule (<hr>, or "---" in markdown). This works with the default theme. If you insert horizontal rules in your markdown, you will need to change the code. If you use a different theme, you will need to check if and where it places horizontal rules.
*/

// EDIT this variable
var myResponseText = 'Responses welcome on Read Write.as using &#35;<a href="https://read.write.as/t/username">username</a>';


// Insert response hashtag on posts, but not on the homepage
// Check for post body id
if(document.getElementById("post-body")){

var content = document.getElementById("post-body").innerHTML;

var result = /responseno/i.test(content);

if (result) {
    var MyResponseTag = '<div style="margin-bottom: 2rem"><h3>No Responses Please</h3></div>';

var newContent = content.replace(/responseno/gi, "");

document.getElementById("post-body").innerHTML = newContent;

document.getElementsByTagName("hr")[0].insertAdjacentHTML('beforeBegin', MyResponseTag);
  }
  else {
    var MyResponseTag = '<div style="margin-bottom: 2rem"><h3>'+myResponseText+'</h3></div>';

document.getElementsByTagName("hr")[0].insertAdjacentHTML('beforeBegin', MyResponseTag);
  }
} else {

// remove responseno flag from homepage if displayed as part of post preview

 var bodyContent = document.getElementsByTagName("body")[0].innerHTML;

 var newBodyContent = bodyContent.replace(/responseno/gi, "");

 document.body.innerHTML = newBodyContent;

}
2 Likes