User:Narmdo/common.js

var pageContent = mw.hook('wikipage.content');

function map($class, $function) {	pageContent.add(function($content) {	   var $items = $content.find($class);	    if (!$items.length) return;	    $items.each(function { var $this = $(this); $function($this); });	}); }

map('.att-news', function($div) {	var blogApi = "https://strapi.townshiptale.dev/graphql?query={posts(limit:7,%20sort:%22date:desc%22){title,date,slug}}&format=txt&format=txt&origin=*";

$div = $div.children(":first"); fetch(blogApi) .then(function(response) {return response.json;}) .then(function(response) {	   	var posts = response.data.posts;	    	$div.children('.rss_item').remove;	    	posts.forEach(function($post) {	   		var itemHtml = ' ' + $post.title + ' ' + $post.date + '  ';	    		$div.append(itemHtml); });	    }); });