Editor's note since this is gathering close votes: the code formatting filter is not a Stack Overflow-only feature; it's active on four sites and a CM has stated that questions about it are on-topic here.
EDIT: This seems to be a bug. See my answer below for explanations.
I was trying to post a question to StackOverflow but I keep getting this error message:
Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.
Unfortunately, no useful information is provided (no line-number for the error, etc.)
It took me quite some time to get the formatting right. Now it looks nice, everything seems properly formatted. I have no clue, why I get the error ... :(
I read half a dozen meta threads dealing with the same error, but none of the troubleshooting suggestions work for me.
Below the horizontal line is my text.
You can also see the unformatted source text here:
https://paste.ofcode.org/PntBVXpCTLkSt8Vz265Yb8
Strangely enough, the same text IS accepted here on meta without any error.
I am very grateful for any help.
It would be especially useful if you knew a troubleshooting method for narrowing down the location of the problem.
(PS: some links are replaced with "{link}" due to site limitations)
Hello. Can you help me with my first greasemonkey script? I'm a complete beginner and would be ingenuously thankful for help. I've tried a lot, but always fail.
My text looks quite long, but that's just because I am over-explaining for clarity sake. In truth, the matter is quite simple and I'd think a couple of code lines would suffice.
► In short, I'd like to catch the byline from an Austrian newspaper ("Kurier") article and add it (slightly modified) to the article's print view.
So here is what the greasemonkey script should do (without external scripts such as jquery):
- step 1: upon navigating to an article URL, redirect to the printview URL
- step 2: copy the byline from the article URL
- step 3: modify the byline (see below)
- step 4: paste the byline into the printview page
comments for each step:
[step 1]
The print view of each article is located at [article URL] + "/print"
,
for example:
article URL: {link}
print view URL: {link}
This is the only step, I was able to do successfully myself (lol):
// ==UserScript==
// @name KURIER printview
// @include https://kurier.at/*
// @exclude https://kurier.at/*/print
// @version 1
// @run-at document-start
// ==/UserScript==
window.location.replace(window.location + "/print");
I used @exclude
to avoid an infinite loop.
To not slow down the script, it would be great if @run-at document-start
could be left unchanged, so that the script does not have to render the article page but directly jumps to the printview URL. Hence only 1 page has to be rendered instead of 2 pages.
(My hope being that step 2 can be accomplished from the printview location?
Otherwise can step 2 be accomplished from the article page, but without rendering the article page?
Either method would avoid rendering 2 pages.)
[step 2]
The byline is a div container, which comes in one of 3 different forms (depending on the number of authors):
• no author: <div class="misc no-author">
• single author: <div class="misc single-author has-image">
• multiple authors: <div class="misc multiple-authors">
Here are example articles for each type:
• no author: {link}
• single author: {link}
• multiple authors: {link}
[step 3]
The byline div container has this structure:
<div class="misc [no-author/single-author/multiple-authors]">
|__ [optional content]
|__ <div class="last-modified">
|__ <div class="social-media-container">
|__ <div class="clear">
a) The social media container should be removed.
b) The optional content may include an image.
The image URL scheme is: images.kurier.at/[imagename].jpg/[size]x[size]/[imageID]
If an image is present, the pixel values should be changed from:
<img width="35" height="35" src="https://images.kurier.at/Sandra-
Lumetsberger(2)-REdit.jpg/70x70/133.396.913" alt="Sandra Lumetsberger">
to:
<img width="100" height="100" src="https://images.kurier.at/Sandra-
Lumetsberger(2)-REdit.jpg/200x200/133.396.913" alt="Sandra Lumetsberger">
[step 4]
The printview page has this structure:
<body>
|__ <script>
|__ <div class="wrapper">
|__ <header class="header">
|__ <div class="rfloat noprint">
|__ <p class="open12 marginb10">
|__ <div class="clear">
|__ <article>
The byline div copied in step 2 and modified in step 3 should be pasted below the p element.
Thank you so very much!