Redirect multi-page news articles to a single page view using Greasemonkey

A lot of news websites split their articles into multiple pages. In theory this drives page impressions and thus ad revenue. In practice it is just annoying. The Greasemonkey script below automagically redirects you to a news article’s full page (in this case on zeit.de). It uses a MutiationObserver to wait for the pager UI element. The script kicks in once it appears – no need to wait until their page (or ads?!) have been fully loaded. 🙂

You can easily modify it:

1. Include all pages that might contain a multi-page article
2. Exclude all pages that might lead to a loop (especially the target site) or that will not contain a pager element (MutiationObserver can easily add a couple of milliseconds of loading time on complex pages)
3. Change the class name of the pager element to the one used by your site
4. Change the target location to the one you want to be redirect to

// ==UserScript==
// @name         Zeit Onepager
// @namespace    kubath.com
// @version      1.0
// @description  Zeigt mehrseitige Zeit-Artikel auf einer Seite
// @author       Florian Kubath
// @match        *://www.zeit.de/*
// @exclude      *://www.zeit.de/*/komplettansicht
// @grant        none
// @run-at       document-start
// ==/UserScript==

var mutationObserver;

window.addEventListener('load', function() {
  
  mutationObserver.disconnect();
}, false);

(function onepager() {

    mutationObserver = new MutationObserver(function (mutations) {

        var pager = document.getElementsByClassName('article-pager__all'); // Change to your site's pager element's class name
        if (pager.length > 0) {

            window.location.replace(window.location.href + '/komplettansicht'); // Change to your target site's URL 
            mutationObserver.disconnect();
            return;
        }
    });

    mutationObserver.observe(document, {

        childList: true,
        subtree: true
    });
}());

 

Ready-to-install scripts for:

golem.de
heise.de
zeit.de

The easiest way to send basic HTTP POST or GET requests using PHP

The easiest way to send basic HTTP POST or GET requests is using PHP’s built in file_get_contents() function in conjunction with HTTP context options:

$data = http_build_query(
    array(
        'firstKey' => 'firstValue',
        'secondKey' => 'secondValue',
        'thirdKey' => 'thirdValue'
    )
);

$options = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $data
    )
);

$context = stream_context_create($options);

$result = file_get_contents('https://httpbin.org/post', false, $context);

Further reading:

file_get_contents
HTTP context options

Stepscout: A tool to search for jobs and apartments at the same time

I think living near one’s workplace is a great benefit for a good work-live balance. If you are living in your current city for a while, you probably already know where the best places to live and work are. But if you are starting to search for one or the other, you might ask yourself which neighborhood is the best to reduce the daily commute to a minimum. To find answers to this question I build Stepscout. It leverages the Stepstone and ImmobilienScout24 API’s to find jobs & apartments in one go and marks them together on a Google Map. This visualization helps to find job clusters, apartment clusters or ideally job-apartment-clusters.

The trick in this project was to make use of Google’s Places API to search for latitude and longitude of every company in the Stepstone result response. Even though Stepstone’s response JSON contains fields for geographic coordinates, they are empty or filled with generic values for the most part.

If you are living in Germany, you can check out the tool here or get a first impression below.