I have written a Javascript to test, and it seems to work fine for basic elements — text and fill/stroke on object, applied through styles.
It does not work for items on a master page (you have to override these) and for bulleted lists (you have to convert these to text). It also doesn't work on table and cell styles, but theoretically that should be possible as well — I left it out for now because it's a bit more work ;-)
But it requires discipline in your document setup and style usage!
- First, you create swatches named “Page 1”, “Page 2”, “Page 3/4”, “Page 5/6/20”, and so on. The “x/y” notation lists multiple pages where the same swatch may be used — sorry, no niceties such as “Page 5-20” or “Page xxiv and xxvi up to the end” are allowed.
- You create one single swatch called “Color Placeholder”. Make it a bright “bad” color (I suggest Hot Pink) so it's clearly visible when applied.
- You apply this color only and exclusively through paragraph styles, character styles, and object styles. You cannot apply it directly to text or objects; that is because the applied color will get changed by the script, but the style color (“Color Placeholder”) will still be 'underneath'.
- If you run the script, it scans all paragraph, character, and object styles for a fill color “Color Placeholder”, and for object styles also a stroke color “Color Placeholder”. If it finds a style with that color in the definition, it finds all occurrences where that style was applied, checks on what page it occurs, and changes the color in place — leaving the style unchanged.
It's important that it changes the color “in place”, by directly changing the applied color. That's so you can run the script again, after inserting or removing pages, and editing text, and that's why you have to apply the color through styles.
It's also important that you actually define a swatch for every page — if the script cannot find a color for page x, all items on that page will remain in their original color (Hot Pink, or one that was assigned in a previous run).
You can download the test script by right-clicking here; select “Save Target As” (or equivalent) and save it right into your User Script folder. Don't forget to create the swatches and set up your styles before running!