Skip to content

Instantly share code, notes, and snippets.

@o-jasper
Created April 5, 2016 00:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o-jasper/df6f93e8c1a9ec8d3ff59f0266dfe368 to your computer and use it in GitHub Desktop.
Save o-jasper/df6f93e8c1a9ec8d3ff59f0266dfe368 to your computer and use it in GitHub Desktop.
Userscript for making it show titles on Arxiv pdfs.
// ==UserScript==
// @name Arxiv titlatorizer
// @namespace Titlatorizer
// @description Replaces the arxiv title with the ... title.
// @include http://arxiv.org/*
// @include https://arxiv.org/*
// @version 0.0
// @grant GM_xmlhttpRequest
// ==/UserScript==
//
// By Jasper den Ouden, based on
// https://github.com/musically-ut/arXiv-title-fixerarXiv-title-fixer
// by Utkarsh Upadhyay on MIT license
//
// MIT license is repeated below although relatively little is copied here.
function figure_title_from_xml(xml) {
var feed = xml.childNodes[0];
var paper_title = null;
Array.prototype.slice.call(feed.children).forEach(function (child) {
if (child.nodeName.toLowerCase() === 'entry') {
var entry = child;
Array.prototype.slice.call(entry.children).forEach(function (field) {
if (field.nodeName.toLowerCase() === 'title') {
var title = field;
paper_title = title.childNodes[0].wholeText;
}
});
}
});
return paper_title;
}
function figure_title() {
var pathComponents = window.location.pathname.split('/');
var pdfName = pathComponents[pathComponents.length - 1];
var paperId = /([^v]*)(v[0-9]*)?\.pdf/.exec(pdfName)[1];
if(paperId) {
GM_xmlhttpRequest({
method:'GET',
url:"http://export.arxiv.org/api/query?id_list=" + paperId,
onload:function (response) {
if (response.status === 200) {
var responseXML =
(new DOMParser()).parseFromString(response.responseText, "text/xml");
var title = figure_title_from_xml(responseXML);
if(title){ document.title = title + " (" + paperId + ")"; }
};
}
});
}
}
figure_title();
// The MIT License (MIT)
//
// Copyright (c) 2016 Utkarsh Upadhyay
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
@munael
Copy link

munael commented Oct 7, 2020

It changes the title at first... But once the file is fully loaded, Chrome overrides it. Quite frustrating :/
I can't get it to wait till "page load" first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment