sjehuda / F-Droid Title Fixer

// ==UserScript== 
// @name        F-Droid Title Fixer
// @namespace   org.bookmark.proper.f-droid
// @description Set f-droid.org page title and description
// @grant       none
// @include     https://f-droid.org/repository/browse/?fdfilter=*
// @include     https://f-droid.org/repository/browse/?fdid=*
// @version     1.0.0
// @icon        https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/F-Droid_Logo_4.svg/48px-F-Droid_Logo_4.svg.png
// ==/UserScript==

var metaDescription, metaElement, pageTitle;

// locate desired title
pageTitle = document.evaluate('//div[@id="appheader"]/p/span/text()', document, null, XPathResult.STRING_TYPE, null );

// adjust title
pageTitle = pageTitle.stringValue + ' – F-Droid';

// overwrite (set) page title
document.title = pageTitle;

// create element meta
metaElement = document.createElement('meta');

// append element
document.head.appendChild(metaElement);

// detect appended element meta
metaElement = document.querySelector('meta:last-of-type');

// set attribute description
metaElement.setAttribute('name', 'description');

// locate desired description
metaDescription = document.evaluate('//div[@id="appheader"]/p/text()', document, null, XPathResult.STRING_TYPE, null );

// set desired description as attribute content
metaElement.setAttribute('content', metaDescription.stringValue);